ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-07-31 04:29:18
Exec Total Coverage
Lines: 2014 4566 44.1%
Functions: 142 337 42.1%
Branches: 1341 3760 35.7%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/replay_upload.h"
27 #include "zc/zc_init.h"
28 #include "init.h"
29 #include "zc/replay.h"
30 #include "zc/cheats.h"
31 #include "zc/render.h"
32 #include "base/zc_math.h"
33 #include "base/zapp.h"
34 #include "dialog/cheatkeys.h"
35 #include "metadata/metadata.h"
36 #include "zc/zelda.h"
37 #include "zc/saves.h"
38 #include "tiles.h"
39 #include "base/colors.h"
40 #include "pal.h"
41 #include "base/zsys.h"
42 #include "base/qst.h"
43 #include "zc/zc_sys.h"
44 #include "play_midi.h"
45 #include "gui/jwin_a5.h"
46 #include "base/jwinfsel.h"
47 #include "base/gui.h"
48 #include "midi.h"
49 #include "subscr.h"
50 #include "zc/maps.h"
51 #include "sprite.h"
52 #include "zc/guys.h"
53 #include "zc/hero.h"
54 #include "zc/title.h"
55 #include "particles.h"
56 #include "sound/zcmusic.h"
57 #include "zc/ffscript.h"
58 #include "dialog/info.h"
59 #include "dialog/alert.h"
60 #include "zc/combos.h"
61 #include "zc/jit.h"
62 #include "zc/zc_subscr.h"
63 #include <fmt/format.h>
64 #include "zconsole/ConsoleLogger.h"
65 #include "zinfo.h"
66 #include "base/misctypes.h"
67 #include "music_playback.h"
68 #include "base/new_menu.h"
69 #include "base/files.h"
70 #include "iter.h"
71
72 #ifdef __EMSCRIPTEN__
73 #include "base/emscripten_utils.h"
74 #endif
75
76 using namespace std::chrono_literals;
77
78 extern bool Playing;
79 int32_t sfx_voice[WAV_COUNT];
80 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
81 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
82
83 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
84 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
85
86 extern byte monochrome_console;
87
88 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
89 extern std::string loadlast;
90 extern char *sfx_string[WAV_COUNT];
91 byte use_dwm_flush;
92 byte use_save_indicator;
93 int32_t paused_midi_pos = 0;
94 byte midi_suspended = 0;
95 byte zc_192b163_warp_compatibility;
96 bool epilepsyFlashReduction;
97 signed char pause_in_background_menu_init = 0;
98 byte pause_in_background = 0;
99 bool is_sys_pal = false;
100 static bool load_control_called_this_frame;
101 extern PALETTE* hw_palette;
102 extern bool update_hw_pal;
103 extern const char* dmaplist(int32_t index, int32_t* list_size);
104 int32_t getnumber(const char *prompt,int32_t initialval);
105
106 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
107 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
108
109 #ifdef ALLEGRO_LINUX
110 static const char *samplepath = "samplesoundset/patches.dat";
111 #endif
112 char qst_files_path[2048];
113
114 extern TopMenu the_player_menu;
115 #ifdef _MSC_VER
116 #define getcwd _getcwd
117 #endif
118
119 bool rF11();
120 bool rI();
121 bool rQ();
122 bool zc_key_pressed();
123
124 #ifdef _WIN32
125
126 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
127 extern "C"
128 {
129 typedef HRESULT(WINAPI *t_DwmFlush)();
130 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
131 }
132
133 void do_DwmFlush()
134 {
135 static HMODULE shell = LoadLibrary("dwmapi.dll");
136
137 if(!shell)
138 return;
139
140 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
141 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
142
143 BOOL enabled;
144 isEnabled(&enabled);
145
146 if(isEnabled)
147 flush();
148 }
149
150 #endif // _WIN32
151
152 314 void zc_exit(int code)
153 {
154 extern CConsoleLoggerEx zscript_coloured_console;
155
156 314 set_is_exiting();
157
158
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if (replay_get_mode() == ReplayMode::Record) replay_save();
159 314 replay_stop();
160 314 music_stop();
161 314 kill_sfx();
162
163
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 306 times.
314 if (get_qr(qr_OLD_SCRIPT_VOLUME))
164 {
165 //restore user volume settings
166
2/2
✓ Branch 0 taken 305 times.
✓ Branch 1 taken 1 times.
306 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
167 {
168 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
169 1 }
170
2/2
✓ Branch 0 taken 305 times.
✓ Branch 1 taken 1 times.
306 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
171 {
172 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
173 1 }
174
2/2
✓ Branch 0 taken 305 times.
✓ Branch 1 taken 1 times.
306 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
175 {
176 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
177 1 }
178
1/2
✓ Branch 0 taken 306 times.
✗ Branch 1 not taken.
306 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
179 {
180 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
181 }
182 306 }
183
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
184 {
185 pan_style = (int32_t)FFCore.usr_panstyle;
186 }
187 314 save_game_configs();
188
189 314 zscript_coloured_console.kill();
190 314 jit_shutdown();
191 314 quit_game();
192
193 314 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
194 314 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
195
196 314 allegro_exit();
197 314 exit(code);
198 }
199
200 93132 bool flash_reduction_enabled(bool check_qr)
201 {
202
4/4
✓ Branch 0 taken 88452 times.
✓ Branch 1 taken 4680 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92304 times.
93132 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
203 }
204
205 // Dialogue largening
206 void large_dialog(DIALOG *d)
207 {
208 large_dialog(d, 1.5);
209 }
210
211 void large_dialog(DIALOG *d, float RESIZE_AMT)
212 {
213 if(!d[0].d1)
214 {
215 d[0].d1 = 1;
216 int32_t oldwidth = d[0].w;
217 int32_t oldheight = d[0].h;
218 int32_t oldx = d[0].x;
219 int32_t oldy = d[0].y;
220 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
221 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
222 d[0].w = int32_t(d[0].w*RESIZE_AMT);
223 d[0].h = int32_t(d[0].h*RESIZE_AMT);
224
225 for(int32_t i=1; d[i].proc !=NULL; i++)
226 {
227 // Place elements horizontally
228 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
229 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
230
231 if(d[i].proc != d_stringloader)
232 {
233 if(d[i].proc==d_bitmap_proc)
234 {
235 d[i].w *= 2;
236 }
237 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
238 }
239
240 // Place elements vertically
241 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
242 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
243
244 // Vertically resize elements
245 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
246 {
247 d[i].h = int32_t((double)d[i].h*1.5);
248 }
249 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
250 {
251 d[i].y += int32_t((double)d[i].h*0.25);
252 d[i].h = int32_t((double)d[i].h*1.25);
253 }
254 else if(d[i].proc==d_bitmap_proc)
255 {
256 d[i].h *= 2;
257 }
258 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
259
260 // Fix frames
261 if(d[i].proc == jwin_frame_proc)
262 {
263 d[i].x++;
264 d[i].y++;
265 d[i].w-=4;
266 d[i].h-=4;
267 }
268 }
269 }
270
271 for(int32_t i=1; d[i].proc!=NULL; i++)
272 {
273 if(d[i].proc==jwin_slider_proc)
274 continue;
275
276 // Bigger font
277 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
278
279 if(!d[i].dp2 && bigfontproc)
280 {
281 d[i].dp2 = get_zc_font(font_lfont_l);
282 }
283 else if(!bigfontproc)
284 {
285 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
286 }
287
288 // Make checkboxes work
289 if(d[i].proc == jwin_check_proc)
290 d[i].proc = jwin_checkfont_proc;
291 else if(d[i].proc == jwin_radio_proc)
292 d[i].proc = jwin_radiofont_proc;
293 }
294
295 jwin_center_dialog(d);
296 }
297
298 static char cfg_sect[] = "zeldadx"; //We need to rename this.
299 static char ctrl_sect[] = "Controls";
300 static char sfx_sect[] = "Volume";
301
302 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
303 {
304 return D_O_K;
305 }
306
307 bool is_reserved_key(int c)
308 {
309 switch(c)
310 {
311 case KEY_ESC:
312 return true;
313 }
314 return false;
315 }
316 bool is_reserved_keycombo(int c, int modflag)
317 {
318 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
319 return true;
320 return false;
321 }
322 bool checkcheat(Cheat cheat)
323 {
324 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
325 return true; //Main key pressed
326 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
327 return true; //Alt key pressed
328 return false;
329 }
330 314 void load_default_cheatkeys()
331 {
332 314 memset(cheatkeys, 0, sizeof(cheatkeys));
333 314 cheatkeys[Cheat::Life][0] = KEY_H;
334 314 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
335 314 cheatkeys[Cheat::Magic][0] = KEY_M;
336 314 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
337 314 cheatkeys[Cheat::Rupies][0] = KEY_R;
338 314 cheatkeys[Cheat::Bombs][0] = KEY_B;
339 314 cheatkeys[Cheat::Arrows][0] = KEY_A;
340 314 cheatkeys[Cheat::Clock][0] = KEY_I;
341 314 cheatkeys[Cheat::Walls][0] = KEY_F11;
342 314 cheatkeys[Cheat::Fast][0] = KEY_Q;
343 314 cheatkeys[Cheat::Light][0] = KEY_L;
344 314 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
345 314 cheatkeys[Cheat::Kill][0] = KEY_K;
346 314 cheatkeys[Cheat::GoTo][0] = KEY_G;
347 314 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
348 314 cheatkeys[Cheat::ShowL0][0] = KEY_0;
349 314 cheatkeys[Cheat::ShowL1][0] = KEY_1;
350 314 cheatkeys[Cheat::ShowL2][0] = KEY_2;
351 314 cheatkeys[Cheat::ShowL3][0] = KEY_3;
352 314 cheatkeys[Cheat::ShowL4][0] = KEY_4;
353 314 cheatkeys[Cheat::ShowL5][0] = KEY_5;
354 314 cheatkeys[Cheat::ShowL6][0] = KEY_6;
355 314 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
356 314 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
357 314 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
358 314 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
359 314 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
360 314 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
361 314 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
362 314 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
363 314 }
364
365 static bool loaded_game_configs;
366
367 314 void load_game_configs()
368 {
369 314 loaded_game_configs = true;
370 314 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
371 314 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
372 314 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
373 314 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
374 314 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
375 314 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
376 314 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
377 314 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
378 314 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
379 314 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
380 314 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
381 314 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
382 314 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
383 314 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
384
385 //cheat modifier keya
386 314 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
387 314 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
388 314 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
389 314 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
390
391 //cheat keys
392 314 load_default_cheatkeys();
393 char buf[256];
394
2/2
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 11304 times.
11618 for(size_t q = 1; q < Cheat::Last; ++q)
395 {
396
1/2
✓ Branch 0 taken 11304 times.
✗ Branch 1 not taken.
11304 if(!bindable_cheat((Cheat)q)) continue;
397 11304 std::string cheatname = cheat_to_string((Cheat)q);
398
1/2
✓ Branch 0 taken 11304 times.
✗ Branch 1 not taken.
11304 util::lowerstr(cheatname);
399 11304 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
400
1/2
✓ Branch 0 taken 11304 times.
✗ Branch 1 not taken.
11304 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
401 11304 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
402
1/2
✓ Branch 0 taken 11304 times.
✗ Branch 1 not taken.
11304 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
403 11304 }
404
405
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
406 joystick_index = 0;
407
408 314 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
409 314 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
410 314 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
411 314 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
412 314 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
413 314 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
414 314 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
415 314 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
416 314 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
417 314 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
418
419 314 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
420 314 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
421 314 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
422 314 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
423
424 314 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
425 314 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
426 314 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
427 314 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
428 314 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
429 314 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
430 314 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
431 314 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
432 314 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
433 314 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
434 314 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
435
436 314 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
437 314 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
438 314 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
439 314 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
440
441 314 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
442
443 314 midi_volume = zc_get_config(sfx_sect,"midi",255);
444 314 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
445 314 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
446 314 pan_style = zc_get_config(sfx_sect,"pan",1);
447 314 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
448 314 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
449 314 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
450 314 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
451 314 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
452 314 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
453 314 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
454 314 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
455 314 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
456 #ifdef __EMSCRIPTEN__
457 if (em_is_mobile()) NameEntryMode = 2;
458 #endif
459 314 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
460 314 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
461 314 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
462 314 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
463 314 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
464 314 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
465
466 314 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
467 314 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
468 314 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
469 314 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
470 314 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
471 314 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
472 314 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
473
474 314 loadlast = zc_get_config(cfg_sect,"load_last_path","");
475
476 314 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
477
478 314 info_opacity = zc_get_config("zc","debug_info_opacity",255);
479 #ifdef _WIN32
480 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
481 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
482 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
483
484 // This one's for Aero
485 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
486
487 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
488 #else //UNIX
489 314 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
490 314 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
491 #endif
492 314 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
493 314 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
494
495 314 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
496 314 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
497 314 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
498 314 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
499 314 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
500 314 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
501 314 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
502 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
503 314 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
504 314 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
505 314 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
506 314 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
507 314 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
508 314 }
509
510 void save_control_configs(bool kb)
511 {
512 if(kb)
513 {
514 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
515 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
516 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
517 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
518
519 if (!replay_is_replaying())
520 {
521 zc_set_config(ctrl_sect,"key_a",Akey);
522 zc_set_config(ctrl_sect,"key_b",Bkey);
523 zc_set_config(ctrl_sect,"key_s",Skey);
524 zc_set_config(ctrl_sect,"key_l",Lkey);
525 zc_set_config(ctrl_sect,"key_r",Rkey);
526 zc_set_config(ctrl_sect,"key_p",Pkey);
527 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
528 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
529 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
530 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
531 zc_set_config(ctrl_sect,"key_up", DUkey);
532 zc_set_config(ctrl_sect,"key_down", DDkey);
533 zc_set_config(ctrl_sect,"key_left", DLkey);
534 zc_set_config(ctrl_sect,"key_right",DRkey);
535 }
536 }
537 else
538 {
539 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
540 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
541 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
542 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
543 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
544 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
545 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
546 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
547 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
548 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
549 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
550 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
551 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
552 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
553
554 zc_set_config(ctrl_sect,"btn_a",Abtn);
555 zc_set_config(ctrl_sect,"btn_b",Bbtn);
556 zc_set_config(ctrl_sect,"btn_s",Sbtn);
557 zc_set_config(ctrl_sect,"btn_m",Mbtn);
558 zc_set_config(ctrl_sect,"btn_l",Lbtn);
559 zc_set_config(ctrl_sect,"btn_r",Rbtn);
560 zc_set_config(ctrl_sect,"btn_p",Pbtn);
561 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
562 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
563 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
564 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
565
566 zc_set_config(ctrl_sect,"btn_up",DUbtn);
567 zc_set_config(ctrl_sect,"btn_down",DDbtn);
568 zc_set_config(ctrl_sect,"btn_left",DLbtn);
569 zc_set_config(ctrl_sect,"btn_right",DRbtn);
570 }
571 }
572
573 void save_cheatkeys()
574 {
575 char buf[256];
576 for(size_t q = 1; q < Cheat::Last; ++q)
577 {
578 if(!bindable_cheat((Cheat)q)) continue;
579 std::string cheatname = cheat_to_string((Cheat)q);
580 util::lowerstr(cheatname);
581 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
582 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
583 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
584 if(cheatkeys[q][1])
585 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
586 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
587 }
588 }
589
590 314 void save_game_configs()
591 {
592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
314 if (!loaded_game_configs) return;
593
594 314 packfile_password("");
595
596
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
314 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
597 {
598 int o_window_x, o_window_y;
599 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
600 zc_set_config(cfg_sect,"window_x",o_window_x);
601 zc_set_config(cfg_sect,"window_y",o_window_y);
602 }
603
604
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
314 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
605 {
606 window_width = al_get_display_width(all_get_display());
607 window_height = al_get_display_height(all_get_display());
608 zc_set_config(cfg_sect,"window_width",window_width);
609 zc_set_config(cfg_sect,"window_height",window_height);
610 }
611
612 314 zc_set_config(cfg_sect,"load_last_path",loadlast.c_str());
613 314 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
614
615 314 flush_config_file();
616 #ifdef __EMSCRIPTEN__
617 em_sync_fs();
618 #endif
619 314 }
620
621 //----------------------------------------------------------------
622
623 // Timers
624
625 40049 void fps_callback()
626 {
627 40049 lastfps=framecnt;
628 40049 framecnt=0;
629 40049 }
630
631 END_OF_FUNCTION(fps_callback)
632
633 314 int32_t Z_init_timers()
634 {
635 static bool didit = false;
636 const static char *err_str = "Couldn't allocate timer";
637 314 err_str = err_str; //Unused variable warning
638
639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
314 if(didit)
640 return 1;
641
642 314 didit = true;
643
644 LOCK_VARIABLE(lastfps);
645 LOCK_VARIABLE(framecnt);
646 LOCK_FUNCTION(fps_callback);
647
648
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
649 return 0;
650
651 314 return 1;
652 314 }
653
654 314 void Z_remove_timers()
655 {
656 314 remove_int(fps_callback);
657 314 }
658
659 //----------------------------------------------------------------
660
661 void go()
662 {
663 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
664 }
665
666 void comeback()
667 {
668 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
669 }
670
671 void dump_pal(BITMAP *dest)
672 {
673 for(int32_t i=0; i<256; i++)
674 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
675 }
676
677 //----------------------------------------------------------------
678
679 int game_mouse_index = ZCM_BLANK;
680 static bool system_mouse = false;
681 92 bool sys_mouse()
682 {
683 92 system_mouse = true;
684 92 return MouseSprite::set(ZCM_NORMAL);
685 }
686 1620 bool game_mouse()
687 {
688 1620 system_mouse = false;
689 1620 return MouseSprite::set(game_mouse_index);
690 }
691 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
692 {
693 if(!bmp)
694 return;
695 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
696 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
697 if(bmp->w == scaledw && bmp->h == scaledh)
698 user_scale = false;
699 if(user_scale || sys_recolor)
700 {
701 if(!user_scale) scale = 1;
702 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
703 if(user_scale)
704 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
705 else
706 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
707 if(sys_recolor)
708 recolor_mouse(tmpbmp);
709 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
710 destroy_bitmap(tmpbmp);
711 }
712 else
713 {
714 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
715 }
716 }
717
718 //Handles converting the mouse sprite from the .dat file
719 void recolor_mouse(BITMAP* bmp)
720 {
721 for(int32_t x = 0; x < bmp->w; ++x)
722 {
723 for(int32_t y = 0; y < bmp->h; ++y)
724 {
725 int32_t color = getpixel(bmp, x, y);
726 switch(color)
727 {
728 case dvc(1):
729 color = jwin_pal[jcCURSORMISC];
730 break;
731 case dvc(2):
732 color = jwin_pal[jcCURSOROUTLINE];
733 break;
734 case dvc(3):
735 color = jwin_pal[jcCURSORLIGHT];
736 break;
737 case dvc(5):
738 color = jwin_pal[jcCURSORDARK];
739 break;
740 default:
741 continue;
742 }
743 putpixel(bmp, x, y, color);
744 }
745 }
746 }
747 void load_mouse()
748 {
749 PALETTE pal;
750 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
751 if (!cursor_bitmap)
752 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
753
754 enter_sys_pal();
755 MouseSprite::set(-1);
756 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
757 int32_t sz = 16*scale;
758 for(int32_t j = 0; j < 1; ++j)
759 {
760 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
761 if(zcmouse[j])
762 destroy_bitmap(zcmouse[j]);
763 zcmouse[j] = create_bitmap_ex(8,sz,sz);
764 clear_bitmap(zcmouse[j]);
765 clear_bitmap(tmpbmp);
766 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
767 recolor_mouse(tmpbmp);
768 if(sz!=16)
769 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
770 else
771 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
772 destroy_bitmap(tmpbmp);
773 }
774 if(!hw_palette) hw_palette = &RAMpal;
775 zc_set_palette(*hw_palette);
776
777 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
778 clear_bitmap(blankmouse);
779
780 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
781 MouseSprite::assign(ZCM_BLANK, blankmouse);
782 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
783
784 //Reload the mouse
785 if(system_mouse)
786 sys_mouse();
787 else game_mouse();
788
789 destroy_bitmap(blankmouse);
790 destroy_bitmap(cursor_bitmap);
791 exit_sys_pal();
792 }
793
794 // sets the video mode and initializes the palette and mouse sprite
795 314 bool game_vid_mode(int32_t mode,int32_t wait)
796 {
797
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if (is_headless())
798 314 return true;
799
800 extern int zq_screen_w, zq_screen_h;
801 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
802 {
803 return false;
804 }
805
806 scrx = (resx-320)>>1;
807 scry = (resy-240)>>1;
808 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
809 zcmouse[q] = NULL;
810 load_mouse();
811
812 for(int32_t i=240; i<256; i++)
813 RAMpal[i]=pal_gui[i];
814
815 zc_set_palette(RAMpal);
816 clear_to_color(screen,BLACK);
817
818 rest(wait);
819 return true;
820 314 }
821
822 322 void null_quest()
823 {
824
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 std::string title_assets_path = "modules/classic/title_gfx.dat";
825
2/4
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 322 times.
322 if (get_last_loaded_qstpath() == title_assets_path)
826 return;
827
828 byte skip_flags[4];
829
2/2
✓ Branch 0 taken 322 times.
✓ Branch 1 taken 8372 times.
8694 for (int i = 0; i < skip_max; i++)
830
1/2
✓ Branch 0 taken 8372 times.
✗ Branch 1 not taken.
8372 set_bit(skip_flags, i, 1);
831
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 set_bit(skip_flags, skip_tiles, 0);
832
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 set_bit(skip_flags, skip_csets, 0);
833
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
834
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
835 322 sfxdat = 1;
836 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
837 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
838 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
839 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 322 times.
322 }
841
842 322 void init_NES_mode()
843 {
844 322 null_quest();
845 322 }
846
847 //----------------------------------------------------------------
848
849 qword trianglelines[16]=
850 {
851 0x0000000000000000ULL,
852 0xFD00000000000000ULL,
853 0xFDFD000000000000ULL,
854 0xFDFDFD0000000000ULL,
855 0xFDFDFDFD00000000ULL,
856 0xFDFDFDFDFD000000ULL,
857 0xFDFDFDFDFDFD0000ULL,
858 0xFDFDFDFDFDFDFD00ULL,
859 0xFDFDFDFDFDFDFDFDULL,
860 0x00FDFDFDFDFDFDFDULL,
861 0x0000FDFDFDFDFDFDULL,
862 0x000000FDFDFDFDFDULL,
863 0x00000000FDFDFDFDULL,
864 0x0000000000FDFDFDULL,
865 0x000000000000FDFDULL,
866 0x00000000000000FDULL,
867 };
868
869 word screen_triangles[29][32];
870
871 // the ULL suffixes are to prevent this warning:
872 // warning: integer constant is too large for "int32_t" type
873
874 qword triangles[4][16][8]= //[direction][value][line]
875 {
876 {
877 {
878 0x0000000000000000ULL,
879 0x0000000000000000ULL,
880 0x0000000000000000ULL,
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL
886 },
887 {
888 0xFD00000000000000ULL,
889 0x0000000000000000ULL,
890 0x0000000000000000ULL,
891 0x0000000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL
896 },
897 {
898 0xFDFD000000000000ULL,
899 0xFD00000000000000ULL,
900 0x0000000000000000ULL,
901 0x0000000000000000ULL,
902 0x0000000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL
906 },
907 {
908 0xFDFDFD0000000000ULL,
909 0xFDFD000000000000ULL,
910 0xFD00000000000000ULL,
911 0x0000000000000000ULL,
912 0x0000000000000000ULL,
913 0x0000000000000000ULL,
914 0x0000000000000000ULL,
915 0x0000000000000000ULL
916 },
917 {
918 0xFDFDFDFD00000000ULL,
919 0xFDFDFD0000000000ULL,
920 0xFDFD000000000000ULL,
921 0xFD00000000000000ULL,
922 0x0000000000000000ULL,
923 0x0000000000000000ULL,
924 0x0000000000000000ULL,
925 0x0000000000000000ULL
926 },
927 {
928 0xFDFDFDFDFD000000ULL,
929 0xFDFDFDFD00000000ULL,
930 0xFDFDFD0000000000ULL,
931 0xFDFD000000000000ULL,
932 0xFD00000000000000ULL,
933 0x0000000000000000ULL,
934 0x0000000000000000ULL,
935 0x0000000000000000ULL
936 },
937 {
938 0xFDFDFDFDFDFD0000ULL,
939 0xFDFDFDFDFD000000ULL,
940 0xFDFDFDFD00000000ULL,
941 0xFDFDFD0000000000ULL,
942 0xFDFD000000000000ULL,
943 0xFD00000000000000ULL,
944 0x0000000000000000ULL,
945 0x0000000000000000ULL
946 },
947 {
948 0xFDFDFDFDFDFDFD00ULL,
949 0xFDFDFDFDFDFD0000ULL,
950 0xFDFDFDFDFD000000ULL,
951 0xFDFDFDFD00000000ULL,
952 0xFDFDFD0000000000ULL,
953 0xFDFD000000000000ULL,
954 0xFD00000000000000ULL,
955 0x0000000000000000ULL
956 },
957 {
958 0xFDFDFDFDFDFDFDFDULL,
959 0xFDFDFDFDFDFDFD00ULL,
960 0xFDFDFDFDFDFD0000ULL,
961 0xFDFDFDFDFD000000ULL,
962 0xFDFDFDFD00000000ULL,
963 0xFDFDFD0000000000ULL,
964 0xFDFD000000000000ULL,
965 0xFD00000000000000ULL
966 },
967 {
968 0xFDFDFDFDFDFDFDFDULL,
969 0xFDFDFDFDFDFDFDFDULL,
970 0xFDFDFDFDFDFDFD00ULL,
971 0xFDFDFDFDFDFD0000ULL,
972 0xFDFDFDFDFD000000ULL,
973 0xFDFDFDFD00000000ULL,
974 0xFDFDFD0000000000ULL,
975 0xFDFD000000000000ULL
976 },
977 {
978 0xFDFDFDFDFDFDFDFDULL,
979 0xFDFDFDFDFDFDFDFDULL,
980 0xFDFDFDFDFDFDFDFDULL,
981 0xFDFDFDFDFDFDFD00ULL,
982 0xFDFDFDFDFDFD0000ULL,
983 0xFDFDFDFDFD000000ULL,
984 0xFDFDFDFD00000000ULL,
985 0xFDFDFD0000000000ULL
986 },
987 {
988 0xFDFDFDFDFDFDFDFDULL,
989 0xFDFDFDFDFDFDFDFDULL,
990 0xFDFDFDFDFDFDFDFDULL,
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFD00ULL,
993 0xFDFDFDFDFDFD0000ULL,
994 0xFDFDFDFDFD000000ULL,
995 0xFDFDFDFD00000000ULL
996 },
997 {
998 0xFDFDFDFDFDFDFDFDULL,
999 0xFDFDFDFDFDFDFDFDULL,
1000 0xFDFDFDFDFDFDFDFDULL,
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFD00ULL,
1004 0xFDFDFDFDFDFD0000ULL,
1005 0xFDFDFDFDFD000000ULL
1006 },
1007 {
1008 0xFDFDFDFDFDFDFDFDULL,
1009 0xFDFDFDFDFDFDFDFDULL,
1010 0xFDFDFDFDFDFDFDFDULL,
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFD00ULL,
1015 0xFDFDFDFDFDFD0000ULL
1016 },
1017 {
1018 0xFDFDFDFDFDFDFDFDULL,
1019 0xFDFDFDFDFDFDFDFDULL,
1020 0xFDFDFDFDFDFDFDFDULL,
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFD00ULL
1026 },
1027 {
1028 0xFDFDFDFDFDFDFDFDULL,
1029 0xFDFDFDFDFDFDFDFDULL,
1030 0xFDFDFDFDFDFDFDFDULL,
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL
1036 }
1037 },
1038 {
1039 {
1040 0x0000000000000000ULL,
1041 0x0000000000000000ULL,
1042 0x0000000000000000ULL,
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL
1048 },
1049 {
1050 0x00000000000000FDULL,
1051 0x0000000000000000ULL,
1052 0x0000000000000000ULL,
1053 0x0000000000000000ULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL
1058 },
1059 {
1060 0x000000000000FDFDULL,
1061 0x00000000000000FDULL,
1062 0x0000000000000000ULL,
1063 0x0000000000000000ULL,
1064 0x0000000000000000ULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL
1068 },
1069 {
1070 0x0000000000FDFDFDULL,
1071 0x000000000000FDFDULL,
1072 0x00000000000000FDULL,
1073 0x0000000000000000ULL,
1074 0x0000000000000000ULL,
1075 0x0000000000000000ULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL
1078 },
1079 {
1080 0x00000000FDFDFDFDULL,
1081 0x0000000000FDFDFDULL,
1082 0x000000000000FDFDULL,
1083 0x00000000000000FDULL,
1084 0x0000000000000000ULL,
1085 0x0000000000000000ULL,
1086 0x0000000000000000ULL,
1087 0x0000000000000000ULL
1088 },
1089 {
1090 0x000000FDFDFDFDFDULL,
1091 0x00000000FDFDFDFDULL,
1092 0x0000000000FDFDFDULL,
1093 0x000000000000FDFDULL,
1094 0x00000000000000FDULL,
1095 0x0000000000000000ULL,
1096 0x0000000000000000ULL,
1097 0x0000000000000000ULL
1098 },
1099 {
1100 0x0000FDFDFDFDFDFDULL,
1101 0x000000FDFDFDFDFDULL,
1102 0x00000000FDFDFDFDULL,
1103 0x0000000000FDFDFDULL,
1104 0x000000000000FDFDULL,
1105 0x00000000000000FDULL,
1106 0x0000000000000000ULL,
1107 0x0000000000000000ULL
1108 },
1109 {
1110 0x00FDFDFDFDFDFDFDULL,
1111 0x0000FDFDFDFDFDFDULL,
1112 0x000000FDFDFDFDFDULL,
1113 0x00000000FDFDFDFDULL,
1114 0x0000000000FDFDFDULL,
1115 0x000000000000FDFDULL,
1116 0x00000000000000FDULL,
1117 0x0000000000000000ULL
1118 },
1119 {
1120 0xFDFDFDFDFDFDFDFDULL,
1121 0x00FDFDFDFDFDFDFDULL,
1122 0x0000FDFDFDFDFDFDULL,
1123 0x000000FDFDFDFDFDULL,
1124 0x00000000FDFDFDFDULL,
1125 0x0000000000FDFDFDULL,
1126 0x000000000000FDFDULL,
1127 0x00000000000000FDULL
1128 },
1129 {
1130 0xFDFDFDFDFDFDFDFDULL,
1131 0xFDFDFDFDFDFDFDFDULL,
1132 0x00FDFDFDFDFDFDFDULL,
1133 0x0000FDFDFDFDFDFDULL,
1134 0x000000FDFDFDFDFDULL,
1135 0x00000000FDFDFDFDULL,
1136 0x0000000000FDFDFDULL,
1137 0x000000000000FDFDULL
1138 },
1139 {
1140 0xFDFDFDFDFDFDFDFDULL,
1141 0xFDFDFDFDFDFDFDFDULL,
1142 0xFDFDFDFDFDFDFDFDULL,
1143 0x00FDFDFDFDFDFDFDULL,
1144 0x0000FDFDFDFDFDFDULL,
1145 0x000000FDFDFDFDFDULL,
1146 0x00000000FDFDFDFDULL,
1147 0x0000000000FDFDFDULL
1148 },
1149 {
1150 0xFDFDFDFDFDFDFDFDULL,
1151 0xFDFDFDFDFDFDFDFDULL,
1152 0xFDFDFDFDFDFDFDFDULL,
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0x00FDFDFDFDFDFDFDULL,
1155 0x0000FDFDFDFDFDFDULL,
1156 0x000000FDFDFDFDFDULL,
1157 0x00000000FDFDFDFDULL
1158 },
1159 {
1160 0xFDFDFDFDFDFDFDFDULL,
1161 0xFDFDFDFDFDFDFDFDULL,
1162 0xFDFDFDFDFDFDFDFDULL,
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0x00FDFDFDFDFDFDFDULL,
1166 0x0000FDFDFDFDFDFDULL,
1167 0x000000FDFDFDFDFDULL
1168 },
1169 {
1170 0xFDFDFDFDFDFDFDFDULL,
1171 0xFDFDFDFDFDFDFDFDULL,
1172 0xFDFDFDFDFDFDFDFDULL,
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0x00FDFDFDFDFDFDFDULL,
1177 0x0000FDFDFDFDFDFDULL
1178 },
1179 {
1180 0xFDFDFDFDFDFDFDFDULL,
1181 0xFDFDFDFDFDFDFDFDULL,
1182 0xFDFDFDFDFDFDFDFDULL,
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0x00FDFDFDFDFDFDFDULL
1188 },
1189 {
1190 0xFDFDFDFDFDFDFDFDULL,
1191 0xFDFDFDFDFDFDFDFDULL,
1192 0xFDFDFDFDFDFDFDFDULL,
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL
1198 }
1199 },
1200 {
1201 {
1202 0x0000000000000000ULL,
1203 0x0000000000000000ULL,
1204 0x0000000000000000ULL,
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL
1210 },
1211 {
1212 0x0000000000000000ULL,
1213 0x0000000000000000ULL,
1214 0x0000000000000000ULL,
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0xFD00000000000000ULL
1220 },
1221 {
1222 0x0000000000000000ULL,
1223 0x0000000000000000ULL,
1224 0x0000000000000000ULL,
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0xFD00000000000000ULL,
1229 0xFDFD000000000000ULL
1230 },
1231 {
1232 0x0000000000000000ULL,
1233 0x0000000000000000ULL,
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0xFD00000000000000ULL,
1238 0xFDFD000000000000ULL,
1239 0xFDFDFD0000000000ULL
1240 },
1241 {
1242 0x0000000000000000ULL,
1243 0x0000000000000000ULL,
1244 0x0000000000000000ULL,
1245 0x0000000000000000ULL,
1246 0xFD00000000000000ULL,
1247 0xFDFD000000000000ULL,
1248 0xFDFDFD0000000000ULL,
1249 0xFDFDFDFD00000000ULL
1250 },
1251 {
1252 0x0000000000000000ULL,
1253 0x0000000000000000ULL,
1254 0x0000000000000000ULL,
1255 0xFD00000000000000ULL,
1256 0xFDFD000000000000ULL,
1257 0xFDFDFD0000000000ULL,
1258 0xFDFDFDFD00000000ULL,
1259 0xFDFDFDFDFD000000ULL
1260 },
1261 {
1262 0x0000000000000000ULL,
1263 0x0000000000000000ULL,
1264 0xFD00000000000000ULL,
1265 0xFDFD000000000000ULL,
1266 0xFDFDFD0000000000ULL,
1267 0xFDFDFDFD00000000ULL,
1268 0xFDFDFDFDFD000000ULL,
1269 0xFDFDFDFDFDFD0000ULL
1270 },
1271 {
1272 0x0000000000000000ULL,
1273 0xFD00000000000000ULL,
1274 0xFDFD000000000000ULL,
1275 0xFDFDFD0000000000ULL,
1276 0xFDFDFDFD00000000ULL,
1277 0xFDFDFDFDFD000000ULL,
1278 0xFDFDFDFDFDFD0000ULL,
1279 0xFDFDFDFDFDFDFD00ULL
1280 },
1281 {
1282 0xFD00000000000000ULL,
1283 0xFDFD000000000000ULL,
1284 0xFDFDFD0000000000ULL,
1285 0xFDFDFDFD00000000ULL,
1286 0xFDFDFDFDFD000000ULL,
1287 0xFDFDFDFDFDFD0000ULL,
1288 0xFDFDFDFDFDFDFD00ULL,
1289 0xFDFDFDFDFDFDFDFDULL
1290 },
1291 {
1292 0xFDFD000000000000ULL,
1293 0xFDFDFD0000000000ULL,
1294 0xFDFDFDFD00000000ULL,
1295 0xFDFDFDFDFD000000ULL,
1296 0xFDFDFDFDFDFD0000ULL,
1297 0xFDFDFDFDFDFDFD00ULL,
1298 0xFDFDFDFDFDFDFDFDULL,
1299 0xFDFDFDFDFDFDFDFDULL
1300 },
1301 {
1302 0xFDFDFD0000000000ULL,
1303 0xFDFDFDFD00000000ULL,
1304 0xFDFDFDFDFD000000ULL,
1305 0xFDFDFDFDFDFD0000ULL,
1306 0xFDFDFDFDFDFDFD00ULL,
1307 0xFDFDFDFDFDFDFDFDULL,
1308 0xFDFDFDFDFDFDFDFDULL,
1309 0xFDFDFDFDFDFDFDFDULL
1310 },
1311 {
1312 0xFDFDFDFD00000000ULL,
1313 0xFDFDFDFDFD000000ULL,
1314 0xFDFDFDFDFDFD0000ULL,
1315 0xFDFDFDFDFDFDFD00ULL,
1316 0xFDFDFDFDFDFDFDFDULL,
1317 0xFDFDFDFDFDFDFDFDULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL
1320 },
1321 {
1322 0xFDFDFDFDFD000000ULL,
1323 0xFDFDFDFDFDFD0000ULL,
1324 0xFDFDFDFDFDFDFD00ULL,
1325 0xFDFDFDFDFDFDFDFDULL,
1326 0xFDFDFDFDFDFDFDFDULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL
1330 },
1331 {
1332 0xFDFDFDFDFDFD0000ULL,
1333 0xFDFDFDFDFDFDFD00ULL,
1334 0xFDFDFDFDFDFDFDFDULL,
1335 0xFDFDFDFDFDFDFDFDULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL
1340 },
1341 {
1342 0xFDFDFDFDFDFDFD00ULL,
1343 0xFDFDFDFDFDFDFDFDULL,
1344 0xFDFDFDFDFDFDFDFDULL,
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL
1350 },
1351 {
1352 0xFDFDFDFDFDFDFDFDULL,
1353 0xFDFDFDFDFDFDFDFDULL,
1354 0xFDFDFDFDFDFDFDFDULL,
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL
1360 }
1361 },
1362 {
1363 {
1364 0x0000000000000000ULL,
1365 0x0000000000000000ULL,
1366 0x0000000000000000ULL,
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL
1372 },
1373 {
1374 0x0000000000000000ULL,
1375 0x0000000000000000ULL,
1376 0x0000000000000000ULL,
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x00000000000000FDULL
1382 },
1383 {
1384 0x0000000000000000ULL,
1385 0x0000000000000000ULL,
1386 0x0000000000000000ULL,
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x00000000000000FDULL,
1391 0x000000000000FDFDULL
1392 },
1393 {
1394 0x0000000000000000ULL,
1395 0x0000000000000000ULL,
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x00000000000000FDULL,
1400 0x000000000000FDFDULL,
1401 0x0000000000FDFDFDULL
1402 },
1403 {
1404 0x0000000000000000ULL,
1405 0x0000000000000000ULL,
1406 0x0000000000000000ULL,
1407 0x0000000000000000ULL,
1408 0x00000000000000FDULL,
1409 0x000000000000FDFDULL,
1410 0x0000000000FDFDFDULL,
1411 0x00000000FDFDFDFDULL
1412 },
1413 {
1414 0x0000000000000000ULL,
1415 0x0000000000000000ULL,
1416 0x0000000000000000ULL,
1417 0x00000000000000FDULL,
1418 0x000000000000FDFDULL,
1419 0x0000000000FDFDFDULL,
1420 0x00000000FDFDFDFDULL,
1421 0x000000FDFDFDFDFDULL
1422 },
1423 {
1424 0x0000000000000000ULL,
1425 0x0000000000000000ULL,
1426 0x00000000000000FDULL,
1427 0x000000000000FDFDULL,
1428 0x0000000000FDFDFDULL,
1429 0x00000000FDFDFDFDULL,
1430 0x000000FDFDFDFDFDULL,
1431 0x0000FDFDFDFDFDFDULL
1432 },
1433 {
1434 0x0000000000000000ULL,
1435 0x00000000000000FDULL,
1436 0x000000000000FDFDULL,
1437 0x0000000000FDFDFDULL,
1438 0x00000000FDFDFDFDULL,
1439 0x000000FDFDFDFDFDULL,
1440 0x0000FDFDFDFDFDFDULL,
1441 0x00FDFDFDFDFDFDFDULL
1442 },
1443 {
1444 0x00000000000000FDULL,
1445 0x000000000000FDFDULL,
1446 0x0000000000FDFDFDULL,
1447 0x00000000FDFDFDFDULL,
1448 0x000000FDFDFDFDFDULL,
1449 0x0000FDFDFDFDFDFDULL,
1450 0x00FDFDFDFDFDFDFDULL,
1451 0xFDFDFDFDFDFDFDFDULL
1452 },
1453 {
1454 0x000000000000FDFDULL,
1455 0x0000000000FDFDFDULL,
1456 0x00000000FDFDFDFDULL,
1457 0x000000FDFDFDFDFDULL,
1458 0x0000FDFDFDFDFDFDULL,
1459 0x00FDFDFDFDFDFDFDULL,
1460 0xFDFDFDFDFDFDFDFDULL,
1461 0xFDFDFDFDFDFDFDFDULL
1462 },
1463 {
1464 0x0000000000FDFDFDULL,
1465 0x00000000FDFDFDFDULL,
1466 0x000000FDFDFDFDFDULL,
1467 0x0000FDFDFDFDFDFDULL,
1468 0x00FDFDFDFDFDFDFDULL,
1469 0xFDFDFDFDFDFDFDFDULL,
1470 0xFDFDFDFDFDFDFDFDULL,
1471 0xFDFDFDFDFDFDFDFDULL
1472 },
1473 {
1474 0x00000000FDFDFDFDULL,
1475 0x000000FDFDFDFDFDULL,
1476 0x0000FDFDFDFDFDFDULL,
1477 0x00FDFDFDFDFDFDFDULL,
1478 0xFDFDFDFDFDFDFDFDULL,
1479 0xFDFDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL
1482 },
1483 {
1484 0x000000FDFDFDFDFDULL,
1485 0x0000FDFDFDFDFDFDULL,
1486 0x00FDFDFDFDFDFDFDULL,
1487 0xFDFDFDFDFDFDFDFDULL,
1488 0xFDFDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL
1492 },
1493 {
1494 0x0000FDFDFDFDFDFDULL,
1495 0x00FDFDFDFDFDFDFDULL,
1496 0xFDFDFDFDFDFDFDFDULL,
1497 0xFDFDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL
1502 },
1503 {
1504 0x00FDFDFDFDFDFDFDULL,
1505 0xFDFDFDFDFDFDFDFDULL,
1506 0xFDFDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL
1512 },
1513 {
1514 0xFDFDFDFDFDFDFDFDULL,
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL
1522 }
1523 }
1524 };
1525
1526 static bool is_opening_screen;
1527 int32_t black_opening_count=0;
1528 int32_t black_opening_x,black_opening_y;
1529 int32_t black_opening_shape;
1530
1531 3283 int32_t choose_opening_shape()
1532 {
1533 // First, count how many bits are set
1534 3283 int32_t numBits=0;
1535 int32_t bitCounter;
1536
1537
2/2
✓ Branch 0 taken 16415 times.
✓ Branch 1 taken 3283 times.
19698 for(int32_t i=0; i<bosMAX; i++)
1538 {
1539
2/2
✓ Branch 0 taken 12916 times.
✓ Branch 1 taken 3499 times.
16415 if(COOLSCROLL&(1<<i))
1540 3499 numBits++;
1541 16415 }
1542
1543 // Shouldn't happen...
1544
1/2
✓ Branch 0 taken 3283 times.
✗ Branch 1 not taken.
3283 if(numBits==0)
1545 return bosCIRCLE;
1546
1547 // Pick a bit
1548 3283 bitCounter=zc_rand()%numBits+1;
1549
1550
2/2
✓ Branch 0 taken 4477 times.
✓ Branch 1 taken 26 times.
4503 for(int32_t i=0; i<bosMAX; i++)
1551 {
1552 // If this bit is set, decrement the bit counter
1553
2/2
✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 3413 times.
4477 if(COOLSCROLL&(1<<i))
1554 3413 bitCounter--;
1555
1556 // When the counter hits 0, return a value based on
1557 // which bit it stopped on.
1558 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1559
2/2
✓ Branch 0 taken 3257 times.
✓ Branch 1 taken 1220 times.
4477 if(bitCounter==0)
1560 3257 return i;
1561 1220 }
1562
1563 // Shouldn't be necessary, but the compiler might complain, at least
1564 26 return bosCIRCLE;
1565 3283 }
1566
1567 739 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1568 {
1569 739 x -= viewport.x;
1570 739 y -= viewport.y;
1571
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 729 times.
739 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1572
1573 739 int32_t w=framebuf->w, h=framebuf->h;
1574 739 int32_t blockrows=h/8, blockcolumns=32;
1575 739 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1576
1577
2/2
✓ Branch 0 taken 20692 times.
✓ Branch 1 taken 739 times.
21431 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1578 {
1579
2/2
✓ Branch 0 taken 662144 times.
✓ Branch 1 taken 20692 times.
682836 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1580 {
1581
2/2
✓ Branch 0 taken 273677 times.
✓ Branch 1 taken 388467 times.
662144 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1582 662144 }
1583 20692 }
1584
1585 739 black_opening_count = 66;
1586 739 black_opening_x = x;
1587 739 black_opening_y = y;
1588 739 lensclk = 0;
1589 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1590
1591
1592
1/2
✓ Branch 0 taken 739 times.
✗ Branch 1 not taken.
739 if(black_opening_shape == bosFADEBLACK)
1593 {
1594 refreshTints();
1595 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1596 }
1597
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 14 times.
739 if(wait)
1598 {
1599 14 FFCore.warpScriptCheck();
1600
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 924 times.
938 for(int32_t i=0; i<66; i++)
1601 {
1602 924 draw_screen();
1603 924 advanceframe(true);
1604
1605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 924 times.
924 if(Quit)
1606 {
1607 break;
1608 }
1609 924 }
1610 14 }
1611 739 }
1612
1613 2564 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1614 {
1615 2564 x -= viewport.x;
1616 2564 y -= viewport.y;
1617
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2554 times.
2564 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1618
1619 2564 int32_t w=framebuf->w, h=framebuf->h;
1620 2564 int32_t blockrows=h/8, blockcolumns=32;
1621 2564 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1622
1623
2/2
✓ Branch 0 taken 71899 times.
✓ Branch 1 taken 2564 times.
74463 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1624 {
1625
2/2
✓ Branch 0 taken 2300768 times.
✓ Branch 1 taken 71899 times.
2372667 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1626 {
1627
2/2
✓ Branch 0 taken 1134042 times.
✓ Branch 1 taken 1166726 times.
2300768 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1628 2300768 }
1629 71899 }
1630
1631 2564 black_opening_count = -66;
1632 2564 black_opening_x = x;
1633 2564 black_opening_y = y;
1634 2564 lensclk = 0;
1635
1/2
✓ Branch 0 taken 2564 times.
✗ Branch 1 not taken.
2564 if(black_opening_shape == bosFADEBLACK)
1636 {
1637 refreshTints();
1638 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1639 }
1640
2/2
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 2196 times.
2564 if(wait)
1641 {
1642 2196 FFCore.warpScriptCheck();
1643
2/2
✓ Branch 0 taken 2195 times.
✓ Branch 1 taken 144947 times.
147142 for(int32_t i=0; i<66; i++)
1644 {
1645 144947 draw_screen();
1646 144947 advanceframe(true);
1647
1648
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 144946 times.
144947 if(Quit)
1649 {
1650 1 break;
1651 }
1652 144946 }
1653 2196 }
1654 2564 }
1655
1656 217230 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1657 {
1658 217230 clear_to_color(tmp_scr,BLACK);
1659 217230 int32_t w=dest->w, h=dest->h;
1660
1661
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 1980 times.
✓ Branch 3 taken 20328 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 185286 times.
217230 switch(black_opening_shape)
1662 {
1663 case bosOVAL:
1664 {
1665 9636 double new_w=(w/2)+abs(w/2-x);
1666 9636 double new_h=(h/2)+abs(h/2-y);
1667 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1668 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1669 9636 break;
1670 }
1671
1672 case bosTRIANGLE:
1673 {
1674 1980 double new_w=(w/2)+abs(w/2-x);
1675 1980 double new_h=(h/2)+abs(h/2-y);
1676 1980 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1677 1980 double P2= (PI/2);
1678 1980 double P23=(2*PI/3);
1679 1980 double P43=(4*PI/3);
1680 1980 double Pa= (-4*PI*a/(3*max_a));
1681 1980 double angle=P2+Pa;
1682 1980 double a0=angle;
1683 1980 double a2=angle+P23;
1684 1980 double a4=angle+P43;
1685 3960 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1686 1980 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1687 1980 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1688 0);
1689 1980 break;
1690 }
1691
1692 case bosSMAS:
1693 {
1694
2/2
✓ Branch 0 taken 7260 times.
✓ Branch 1 taken 13068 times.
20328 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1695
1696
2/2
✓ Branch 0 taken 569184 times.
✓ Branch 1 taken 20328 times.
589512 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1697 {
1698
2/2
✓ Branch 0 taken 4553472 times.
✓ Branch 1 taken 569184 times.
5122656 for(int32_t linerow=0; linerow<8; ++linerow)
1699 {
1700 4553472 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1701
1702
2/2
✓ Branch 0 taken 145711104 times.
✓ Branch 1 taken 4553472 times.
150264576 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1703 {
1704 437133312 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1705
6/6
✓ Branch 0 taken 105268072 times.
✓ Branch 1 taken 40443032 times.
✓ Branch 2 taken 96140976 times.
✓ Branch 3 taken 49570128 times.
✓ Branch 4 taken 55697944 times.
✓ Branch 5 taken 40443032 times.
145711104 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1706 145711104 [linerow];
1707 145711104 ++triangleline;
1708 145711104 }
1709 4553472 }
1710 569184 }
1711
1712 20328 break;
1713 }
1714
1715 case bosFADEBLACK:
1716 {
1717 if(black_opening_count<0)
1718 {
1719 black_fade(zc_min(-black_opening_count,63));
1720 }
1721 else if(black_opening_count>0)
1722 {
1723 black_fade(63-zc_max(black_opening_count-3,0));
1724 }
1725 else black_fade(0);
1726 return; //no blitting from tmp_scr!
1727 }
1728
1729 185286 case bosCIRCLE:
1730 default:
1731 {
1732 185286 double new_w=(w/2)+abs(w/2-x);
1733 185286 double new_h=(h/2)+abs(h/2-y);
1734 185286 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1735 //circlefill(tmp_scr,x,y,a<<3,0);
1736 185286 circlefill(tmp_scr,x,y,r,0);
1737 185286 break;
1738 }
1739 }
1740
1741 217230 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1742 217230 }
1743
1744 // fadeamnt is 0-63
1745 void black_fade(int32_t fadeamnt)
1746 {
1747 fadeamnt = _rgb_scale_6[fadeamnt];
1748 for(int32_t i=0; i < 0xEF; i++)
1749 {
1750 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1751 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1752 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1753 }
1754
1755 refreshpal = true;
1756 }
1757
1758 //----------------------------------------------------------------
1759
1760 201534691 bool item_disabled(int32_t item) //is this item disabled?
1761 {
1762
2/2
✓ Branch 0 taken 14507791 times.
✓ Branch 1 taken 187026900 times.
201534691 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1763 }
1764
1765 15648450 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1766 {
1767
2/2
✓ Branch 0 taken 254624 times.
✓ Branch 1 taken 15393826 times.
15648450 if(current_item(item_type, true) >=item)
1768 {
1769 254624 return true;
1770 }
1771
1772 15393826 return false;
1773 15648450 }
1774
1775 43603835 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1776 {
1777
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421257 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 337472 times.
✓ Branch 6 taken 28752761 times.
✓ Branch 7 taken 9897279 times.
✓ Branch 8 taken 195066 times.
43603835 switch(item_type)
1778 {
1779 case itype_bomb:
1780 case itype_sbomb:
1781 {
1782 int32_t itemid = getItemID(itemsbuf, item_type, it);
1783
1784 if(itemid == -1)
1785 return false;
1786
1787 return (game->get_item(itemid));
1788 }
1789
1790 case itype_clock:
1791 {
1792 4421257 int32_t itemid = getItemID(itemsbuf, item_type, it);
1793
1794
2/4
✓ Branch 0 taken 4421257 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421257 times.
✗ Branch 3 not taken.
4421257 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1795 return (game->get_item(itemid));
1796 4421257 return Hero.getClock()?1:0;
1797 }
1798
1799 case itype_key:
1800 return (game->get_keys()>0);
1801
1802 case itype_magiccontainer:
1803 return (game->get_maxmagic()>=game->get_mp_per_block());
1804
1805 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1806 {
1807
1/3
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
337472 switch(it)
1808 {
1809 case -2:
1810 {
1811 for(int32_t i=0; i<MAXLEVELS; i++)
1812 {
1813 if(game->lvlitems[i]&liTRIFORCE)
1814 {
1815 return true;
1816 }
1817 }
1818
1819 return false;
1820 }
1821
1822 case -1:
1823 return (game->lvlitems[dlevel]&liTRIFORCE);
1824
1825 default:
1826
2/4
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 337472 times.
337472 if(it>=0&&it<MAXLEVELS)
1827 {
1828 337472 return (game->lvlitems[it]&liTRIFORCE);
1829 }
1830
1831 break;
1832 }
1833
1834 return 0;
1835 }
1836
1837 case itype_map: //it: -2=any, -1=current level, other=that level
1838 {
1839
2/3
✓ Branch 0 taken 540662 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28212099 times.
28752761 switch(it)
1840 {
1841 case -2:
1842 {
1843 for(int32_t i=0; i<MAXLEVELS; i++)
1844 {
1845 if(game->lvlitems[i]&liMAP)
1846 {
1847 return true;
1848 }
1849 }
1850
1851 return false;
1852 }
1853
1854 case -1:
1855 28212099 return (game->lvlitems[dlevel]&liMAP)!=0;
1856
1857 default:
1858
2/4
✓ Branch 0 taken 540662 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 540662 times.
540662 if(it>=0&&it<MAXLEVELS)
1859 {
1860 540662 return (game->lvlitems[it]&liMAP)!=0;
1861 }
1862
1863 break;
1864 }
1865
1866 return 0;
1867 }
1868
1869 case itype_compass: //it: -2=any, -1=current level, other=that level
1870 {
1871
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9897279 times.
9897279 switch(it)
1872 {
1873 case -2:
1874 {
1875 for(int32_t i=0; i<MAXLEVELS; i++)
1876 {
1877 if(game->lvlitems[i]&liCOMPASS)
1878 {
1879 return true;
1880 }
1881 }
1882
1883 return false;
1884 }
1885
1886 case -1:
1887 9897279 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
1888
1889 default:
1890 if(it>=0&&it<MAXLEVELS)
1891 {
1892 return (game->lvlitems[it]&liCOMPASS)!=0;
1893 }
1894
1895 break;
1896 }
1897 return 0;
1898 }
1899
1900 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1901 {
1902
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 195066 times.
195066 switch(it)
1903 {
1904 case -2:
1905 {
1906 for(int32_t i=0; i<MAXLEVELS; i++)
1907 {
1908 if(game->lvlitems[i]&liBOSSKEY)
1909 {
1910 return true;
1911 }
1912 }
1913
1914 return false;
1915 }
1916
1917 case -1:
1918 195066 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
1919
1920 default:
1921 if(it>=0&&it<MAXLEVELS)
1922 {
1923 return (game->lvlitems[it]&liBOSSKEY)?1:0;
1924 }
1925 break;
1926 }
1927 return 0;
1928 }
1929
1930 default:
1931 int32_t itemid = getItemID(itemsbuf, item_type, it);
1932
1933 if(itemid == -1)
1934 return false;
1935
1936 return game->get_item(itemid);
1937 }
1938 43603835 }
1939
1940 151061242 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1941 {
1942
9/9
✓ Branch 0 taken 4421257 times.
✓ Branch 1 taken 115691186 times.
✓ Branch 2 taken 4421257 times.
✓ Branch 3 taken 4421257 times.
✓ Branch 4 taken 4421257 times.
✓ Branch 5 taken 4421257 times.
✓ Branch 6 taken 4421257 times.
✓ Branch 7 taken 4421257 times.
✓ Branch 8 taken 4421257 times.
151061242 switch(item_type)
1943 {
1944 case itype_clock:
1945 {
1946 4421257 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1947
1948
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4421257 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4421257 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1949 return itemsbuf[maxid].fam_type;
1950
1951 4421257 return has_item(itype_clock,1) ? 1 : 0;
1952 }
1953
1954 case itype_key:
1955 4421257 return game->get_keys();
1956
1957 case itype_lkey:
1958 4421257 return game->lvlkeys[get_dlevel()];
1959
1960 case itype_magiccontainer:
1961 4421257 return game->get_maxmagic()/game->get_mp_per_block();
1962
1963 case itype_triforcepiece:
1964 {
1965 4421257 int count=0;
1966
1967
2/2
✓ Branch 0 taken 2263683584 times.
✓ Branch 1 taken 4421257 times.
2268104841 for(int i=0; i<MAXLEVELS; i++)
1968 {
1969 2263683584 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
1970 2263683584 }
1971
1972 4421257 return count;
1973 }
1974
1975 case itype_map:
1976 {
1977 4421257 int count=0;
1978
1979
2/2
✓ Branch 0 taken 2263683584 times.
✓ Branch 1 taken 4421257 times.
2268104841 for(int i=0; i<MAXLEVELS; i++)
1980 {
1981 2263683584 count+=(game->lvlitems[i]&liMAP)?1:0;
1982 2263683584 }
1983
1984 4421257 return count;
1985 }
1986
1987 case itype_compass:
1988 {
1989 4421257 int count=0;
1990
1991
2/2
✓ Branch 0 taken 2263683584 times.
✓ Branch 1 taken 4421257 times.
2268104841 for(int i=0; i<MAXLEVELS; i++)
1992 {
1993 2263683584 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
1994 2263683584 }
1995
1996 4421257 return count;
1997 }
1998
1999 case itype_bosskey:
2000 {
2001 4421257 int count=0;
2002
2003
2/2
✓ Branch 0 taken 2263683584 times.
✓ Branch 1 taken 4421257 times.
2268104841 for(int i=0; i<MAXLEVELS; i++)
2004 {
2005 2263683584 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2006 2263683584 }
2007
2008 4421257 return count;
2009 }
2010
2011 default:
2012 115691186 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2013
2014
2/2
✓ Branch 0 taken 82001392 times.
✓ Branch 1 taken 33689794 times.
115691186 if(maxid == -1)
2015 82001392 return 0;
2016
2017 33689794 return itemsbuf[maxid].fam_type;
2018 }
2019 151061242 }
2020
2021 411 std::map<int32_t, int32_t> itemcache;
2022 411 std::map<int32_t, int32_t> itemcache_cost;
2023
2024 void removeFromItemCache(int32_t itemclass)
2025 {
2026 itemcache.erase(itemclass);
2027 itemcache_cost.erase(itemclass);
2028 cache_tile_mod_clear();
2029 }
2030
2031 13058732 void flushItemCache(bool justcost)
2032 {
2033 13058732 itemcache_cost.clear();
2034
2/2
✓ Branch 0 taken 12985053 times.
✓ Branch 1 taken 73679 times.
13058732 if(!justcost)
2035 73679 itemcache.clear();
2036
2/2
✓ Branch 0 taken 6357122 times.
✓ Branch 1 taken 6627931 times.
12985053 else if(replay_version_check(0,19))
2037 6357122 return;
2038
2039 6701610 cache_tile_mod_clear();
2040
2041 //also fix the active subscreen if items were deleted -DD
2042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6701610 times.
6701610 if(game != NULL)
2043 {
2044 6701610 verifyBothWeapons();
2045 6701610 refresh_subscr_items();
2046 6701610 }
2047 13058732 }
2048
2049 // This is used often, so it should be as direct as possible.
2050 3025566391 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2051 {
2052 3025566391 bool use_cost_cache = replay_version_check(19);
2053
2/2
✓ Branch 0 taken 2886004502 times.
✓ Branch 1 taken 139561889 times.
3025566391 if(jinx_check)
2054 {
2055 //special case for shields...
2056
3/4
✓ Branch 0 taken 54395870 times.
✓ Branch 1 taken 85166019 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54395870 times.
139561889 if (itemtype == itype_shield && !HeroShieldClk())
2057 54395870 jinx_check = false;
2058
4/4
✓ Branch 0 taken 52519254 times.
✓ Branch 1 taken 32646765 times.
✓ Branch 2 taken 10856084 times.
✓ Branch 3 taken 41663170 times.
85166019 else if(!(HeroSwordClk() || HeroItemClk()))
2059 41663170 jinx_check = false; //not jinxed
2060 139561889 }
2061
4/4
✓ Branch 0 taken 119620 times.
✓ Branch 1 taken 3025446771 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 117767 times.
3025566391 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2062 3025448624 check_bunny = false;
2063
2/2
✓ Branch 0 taken 2967797648 times.
✓ Branch 1 taken 57768743 times.
3025566391 if(itemtype == itype_ring) checkmagic = true;
2064
4/4
✓ Branch 0 taken 2982063542 times.
✓ Branch 1 taken 43502849 times.
✓ Branch 2 taken 297221753 times.
✓ Branch 3 taken 25151626 times.
3347939770 if (!jinx_check && !check_bunny
2065
4/4
✓ Branch 0 taken 2981973383 times.
✓ Branch 1 taken 90159 times.
✓ Branch 2 taken 322373379 times.
✓ Branch 3 taken 2659600004 times.
2982063542 && (use_cost_cache || itemtype != itype_ring))
2066 {
2067
4/4
✓ Branch 0 taken 563353093 times.
✓ Branch 1 taken 2393468664 times.
✓ Branch 2 taken 246727055 times.
✓ Branch 3 taken 316626038 times.
2956821757 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2068 2956821757 auto res = cache.find(itemtype);
2069
2070
2/2
✓ Branch 0 taken 2811249055 times.
✓ Branch 1 taken 145572702 times.
2956821757 if(res != cache.end())
2071 2811249055 return res->second;
2072 145572702 }
2073
2074 214317336 int result = -1;
2075 214317336 int highestlevel = -1;
2076
2077
2/2
✓ Branch 0 taken 54865238016 times.
✓ Branch 1 taken 214317336 times.
55079555352 for(int i=0; i<MAXITEMS; i++)
2078 {
2079
6/6
✓ Branch 0 taken 6000603051 times.
✓ Branch 1 taken 48864634965 times.
✓ Branch 2 taken 96486980 times.
✓ Branch 3 taken 5904116071 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 96404932 times.
54865238016 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2080 {
2081
4/4
✓ Branch 0 taken 91731025 times.
✓ Branch 1 taken 4673907 times.
✓ Branch 2 taken 2473305 times.
✓ Branch 3 taken 89257720 times.
96404932 if(checkmagic && itemtype != itype_magicring)
2082
2/2
✓ Branch 0 taken 89257034 times.
✓ Branch 1 taken 686 times.
89257720 if(!checkmagiccost(i))
2083 686 continue;
2084
6/6
✓ Branch 0 taken 88807857 times.
✓ Branch 1 taken 7596389 times.
✓ Branch 2 taken 1253652 times.
✓ Branch 3 taken 6342737 times.
✓ Branch 4 taken 4146834 times.
✓ Branch 5 taken 3449555 times.
96404246 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3449555 times.
3449555 if(!(itemsbuf[i].flags & item_jinx_immune))
2086 3449555 continue;
2087
3/4
✓ Branch 0 taken 100571 times.
✓ Branch 1 taken 92854120 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100571 times.
92954691 if(check_bunny && !checkbunny(i))
2088 100571 continue;
2089
2090
2/2
✓ Branch 0 taken 8438933 times.
✓ Branch 1 taken 84415187 times.
92854120 if(itemsbuf[i].fam_type >= highestlevel)
2091 {
2092 84415187 highestlevel = itemsbuf[i].fam_type;
2093 84415187 result=i;
2094 84415187 }
2095 92854120 }
2096 54861687204 }
2097
2098
4/4
✓ Branch 0 taken 170814487 times.
✓ Branch 1 taken 43502849 times.
✓ Branch 2 taken 90159 times.
✓ Branch 3 taken 170724328 times.
214317336 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2099 {
2100
2/2
✓ Branch 0 taken 128942451 times.
✓ Branch 1 taken 41781877 times.
170724328 if (use_cost_cache)
2101 {
2102
2/2
✓ Branch 0 taken 113027447 times.
✓ Branch 1 taken 15915004 times.
128942451 if (!checkmagic)
2103 15915004 itemcache[itemtype] = result;
2104
6/6
✓ Branch 0 taken 15915004 times.
✓ Branch 1 taken 113027447 times.
✓ Branch 2 taken 688532 times.
✓ Branch 3 taken 15226472 times.
✓ Branch 4 taken 673569 times.
✓ Branch 5 taken 14963 times.
128942451 if (checkmagic || result < 0 || checkmagiccost(result))
2105 128927488 itemcache_cost[itemtype] = result;
2106 128942451 }
2107 else
2108 {
2109 41781877 itemcache[itemtype] = result;
2110 }
2111 170724328 }
2112 214317336 return result;
2113 3025566391 }
2114
2115 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2116 2982565666 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2117 {
2118
2/4
✓ Branch 0 taken 2982565666 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2982565666 times.
2982565666 if(itype < 0 || itype >= itype_max) return -1;
2119
1/2
✓ Branch 0 taken 2982565666 times.
✗ Branch 1 not taken.
2982565666 if(game->OverrideItems[itype] > -2)
2120 {
2121 auto ovid = game->OverrideItems[itype];
2122 if(ovid < 0 || ovid >= MAXITEMS)
2123 return -1;
2124 if(itemsbuf[ovid].family == itype)
2125 {
2126 if(itype == itype_magicring)
2127 checkmagic = false;
2128 else if(itype == itype_ring)
2129 checkmagic = true;
2130
2131 if(checkmagic && !checkmagiccost(ovid))
2132 return -1;
2133
2134 if (jinx_check && !checkitem_jinx(ovid))
2135 {
2136 return -1;
2137 }
2138 return ovid;
2139 }
2140 }
2141 2982565666 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2142
2/2
✓ Branch 0 taken 96561164 times.
✓ Branch 1 taken 2886004502 times.
2982565666 if(!jinx_check) //If not already a jinx-immune-only check...
2143 {
2144 //And the player IS jinxed...
2145
2/2
✓ Branch 0 taken 2843003777 times.
✓ Branch 1 taken 43000725 times.
2886004502 if(HeroIsJinxed())
2146 {
2147 //Then do a jinx-immune-only check here
2148 43000725 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2149 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2150 //Should NOT need a compat rule, as this should always return -1 in old quests.
2151
2/2
✓ Branch 0 taken 3265892 times.
✓ Branch 1 taken 39734833 times.
43000725 if(ret2 > -1) return ret2;
2152 39734833 }
2153 2882738610 }
2154 2979299774 return ret;
2155 2982565666 }
2156
2157 66327100 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2158 {
2159 66327100 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2160
2/2
✓ Branch 0 taken 35519731 times.
✓ Branch 1 taken 30807369 times.
66327100 return (result<0) ? 0 : itemsbuf[result].power;
2161 }
2162
2163 26 int32_t heart_container_id()
2164 {
2165
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2166 {
2167
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].family == itype_heartcontainer)
2168 {
2169 26 return i;
2170 }
2171 728 }
2172 return -1;
2173 26 }
2174
2175 struct tilemod_cache_state_t
2176 {
2177
6/6
✓ Branch 0 taken 4420901 times.
✓ Branch 1 taken 8544654 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8544652 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8544298 times.
21510209 bool operator==(const tilemod_cache_state_t&) const = default;
2178
2179 bool valid;
2180 bool bunny_clock;
2181 bool superman;
2182 int shield;
2183 };
2184 tilemod_cache_state_t tilemod_cache_state;
2185 int32_t tilemod_cache_value;
2186
2187 6703159 void cache_tile_mod_clear()
2188 {
2189 6703159 tilemod_cache_state = {false};
2190 6703159 }
2191
2192 12965555 int32_t item_tile_mod()
2193 {
2194 51862220 tilemod_cache_state_t state = {
2195 .valid = true,
2196 12965555 .bunny_clock = Hero.BunnyClock() != 0,
2197 12965555 .superman = Hero.superman,
2198 12965555 .shield = Hero.active_shield_id,
2199 };
2200
2/2
✓ Branch 0 taken 8544298 times.
✓ Branch 1 taken 4421257 times.
12965555 if (tilemod_cache_state == state)
2201 8544298 return tilemod_cache_value;
2202
2203 4421257 int32_t tile=0;
2204 4421257 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2205
4/4
✓ Branch 0 taken 4007988 times.
✓ Branch 1 taken 413269 times.
✓ Branch 2 taken 3079195 times.
✓ Branch 3 taken 928793 times.
4421257 if(check_bombcost || game->get_bombs())
2206 {
2207 3492464 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2208
3/4
✓ Branch 0 taken 3432917 times.
✓ Branch 1 taken 59547 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3432917 times.
3492464 if(itemid > -1 && checkbunny(itemid))
2209 3432917 tile+=itemsbuf[itemid].ltm;
2210 3492464 }
2211
2212
4/4
✓ Branch 0 taken 4007988 times.
✓ Branch 1 taken 413269 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 3042690 times.
4421257 if(check_bombcost || game->get_sbombs())
2213 {
2214 1378567 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2215
3/4
✓ Branch 0 taken 965057 times.
✓ Branch 1 taken 413510 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 965057 times.
1378567 if(itemid > -1 && checkbunny(itemid))
2216 965057 tile+=itemsbuf[itemid].ltm;
2217 1378567 }
2218
2219
2/2
✓ Branch 0 taken 4408524 times.
✓ Branch 1 taken 12733 times.
4421257 if(current_item(itype_clock))
2220 {
2221 12733 int32_t itemid =
2222
2/2
✓ Branch 0 taken 12701 times.
✓ Branch 1 taken 32 times.
12733 get_qr(qr_HARDCODED_LITEM_LTMS)
2223 ? iClock
2224 32 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2225
2/4
✓ Branch 0 taken 12733 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12733 times.
12733 if(itemid > -1 && checkbunny(itemid))
2226 12733 tile+=itemsbuf[itemid].ltm;
2227 12733 }
2228
2229
2/2
✓ Branch 0 taken 3775615 times.
✓ Branch 1 taken 645642 times.
4421257 if(current_item(itype_key))
2230 {
2231 645642 int32_t itemid =
2232
2/2
✓ Branch 0 taken 608640 times.
✓ Branch 1 taken 37002 times.
645642 get_qr(qr_HARDCODED_LITEM_LTMS)
2233 ? iKey
2234 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2235
2/4
✓ Branch 0 taken 645642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 645642 times.
645642 if(itemid > -1 && checkbunny(itemid))
2236 645642 tile+=itemsbuf[itemid].ltm;
2237 645642 }
2238
2239
2/2
✓ Branch 0 taken 3920374 times.
✓ Branch 1 taken 500883 times.
4421257 if(current_item(itype_lkey))
2240 {
2241 500883 int32_t itemid =
2242
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 86714 times.
500883 get_qr(qr_HARDCODED_LITEM_LTMS)
2243 ? iLevelKey
2244 86714 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2245
2/4
✓ Branch 0 taken 500883 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500883 times.
500883 if(itemid > -1 && checkbunny(itemid))
2246 500883 tile+=itemsbuf[itemid].ltm;
2247 500883 }
2248
2249
2/2
✓ Branch 0 taken 1586427 times.
✓ Branch 1 taken 2834830 times.
4421257 if(current_item(itype_map))
2250 {
2251 2834830 int32_t itemid =
2252
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10996 times.
2834830 get_qr(qr_HARDCODED_LITEM_LTMS)
2253 ? iMap
2254 10996 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2255
2/4
✓ Branch 0 taken 2834830 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834830 times.
2834830 if(itemid > -1 && checkbunny(itemid))
2256 2834830 tile+=itemsbuf[itemid].ltm;
2257 2834830 }
2258
2259
2/2
✓ Branch 0 taken 2109268 times.
✓ Branch 1 taken 2311989 times.
4421257 if(current_item(itype_compass))
2260 {
2261 2311989 int32_t itemid =
2262
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2263 ? iCompass
2264 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2265
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2266 2311989 tile+=itemsbuf[itemid].ltm;
2267 2311989 }
2268
2269
2/2
✓ Branch 0 taken 1334841 times.
✓ Branch 1 taken 3086416 times.
4421257 if(current_item(itype_bosskey))
2270 {
2271 3086416 int32_t itemid =
2272
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2273 ? iBossKey
2274 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2275
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2276 3086416 tile+=itemsbuf[itemid].ltm;
2277 3086416 }
2278
2279
2/2
✓ Branch 0 taken 48288 times.
✓ Branch 1 taken 4372969 times.
4421257 if(current_item(itype_magiccontainer))
2280 {
2281 4372969 int32_t itemid =
2282
2/2
✓ Branch 0 taken 3904340 times.
✓ Branch 1 taken 468629 times.
4372969 get_qr(qr_HARDCODED_LITEM_LTMS)
2283 ? iMagicC
2284 468629 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2285
3/4
✓ Branch 0 taken 4372969 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4372952 times.
4372969 if(itemid > -1 && checkbunny(itemid))
2286 4372952 tile+=itemsbuf[itemid].ltm;
2287 4372969 }
2288
2289
2/2
✓ Branch 0 taken 1314777 times.
✓ Branch 1 taken 3106480 times.
4421257 if(current_item(itype_triforcepiece))
2290 {
2291 3106480 int32_t itemid =
2292
2/2
✓ Branch 0 taken 3069478 times.
✓ Branch 1 taken 37002 times.
3106480 get_qr(qr_HARDCODED_LITEM_LTMS)
2293 ? iTriforce
2294 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2295
2/4
✓ Branch 0 taken 3106480 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3106480 times.
3106480 if(itemid > -1 && checkbunny(itemid))
2296 3106480 tile+=itemsbuf[itemid].ltm;
2297 3106480 }
2298
2299
2/2
✓ Branch 0 taken 2263683584 times.
✓ Branch 1 taken 4421257 times.
2268104841 for(int32_t i=0; i<itype_max; i++)
2300 {
2301
2/2
✓ Branch 0 taken 2023629312 times.
✓ Branch 1 taken 240054272 times.
2263683584 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2302 {
2303
2/2
✓ Branch 0 taken 4688560 times.
✓ Branch 1 taken 235365712 times.
240054272 switch(i)
2304 {
2305 case itype_bomb:
2306 case itype_sbomb:
2307 case itype_clock:
2308 case itype_key:
2309 case itype_lkey:
2310 case itype_map:
2311 case itype_compass:
2312 case itype_bosskey:
2313 case itype_magiccontainer:
2314 case itype_triforcepiece:
2315 4688560 continue; //already handled
2316 }
2317 235365712 }
2318 2258995024 int32_t itemid = current_item_id(i,false);
2319
2/2
✓ Branch 0 taken 2254573767 times.
✓ Branch 1 taken 4421257 times.
2258995024 if(i == itype_shield)
2320 4421257 itemid = getCurrentShield(false);
2321
2322
4/4
✓ Branch 0 taken 115677455 times.
✓ Branch 1 taken 2143317569 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 115677454 times.
2258995024 if(itemid < 0 || !checkbunny(itemid))
2323 2143317570 continue;
2324
2325 115677454 itemdata const& itm = itemsbuf[itemid];
2326
2327
2/2
✓ Branch 0 taken 111976757 times.
✓ Branch 1 taken 3700697 times.
115677454 switch(itm.family)
2328 {
2329 case itype_shield:
2330
1/2
✓ Branch 0 taken 3700697 times.
✗ Branch 1 not taken.
3700697 if(itm.flags & item_flag9) //active shield
2331 {
2332 if(!usingActiveShield(itemid))
2333 {
2334 tile+=itm.misc6; //'Inactive PTM'
2335 continue;
2336 }
2337 }
2338 3700697 break;
2339 }
2340
2341 115677454 tile+=itm.ltm;
2342 115677454 }
2343
2344 4421257 tilemod_cache_value = tile;
2345 4421257 tilemod_cache_state = state;
2346 4421257 return tile;
2347 12965555 }
2348
2349 12965555 int32_t bunny_tile_mod()
2350 {
2351
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12963685 times.
12965555 if(Hero.BunnyClock())
2352 {
2353 1870 return game->get_bunny_ltm();
2354 }
2355 12963685 return 0;
2356 12965555 }
2357
2358 // Hints are drawn on a separate layer to combo reveals.
2359 // TODO: move out of zc_sys.cpp, weird place for this code.
2360 20058 void draw_lens_under(BITMAP *dest, bool layer)
2361 {
2362 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2363 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2364 //Lens flag 3: Don't show armos/chest/dive items
2365 //Lens flag 4: Show Raft Paths
2366 //Lens flag 5: Show Invisible Enemies
2367
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2368
2369 20058 int32_t strike_hint_table[11]=
2370 {
2371 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2372 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2373 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2374 };
2375
2376 {
2377 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2378 20058 int32_t tempitem, tempweapon=0;
2379 20058 strike_hint=strike_hint_table[strike_hint_counter];
2380
2381
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2382 {
2383 599 strike_hint_timer=0;
2384 599 strike_hint_counter=((strike_hint_counter+1)%11);
2385 599 }
2386
2387 20058 ++strike_hint_timer;
2388
2389 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2390 3530208 mapscr* scr = rpos_handle.scr;
2391 7306676 auto [x, y] = rpos_handle.xy();
2392 7060416 y += playing_field_offset;
2393
2394 3530208 int32_t tempitemx=-16, tempitemy=-16;
2395 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2396
2397
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2398 {
2399 7060416 int32_t checkflag=0;
2400
2401
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2402 {
2403 3530208 checkflag = rpos_handle.cflag();
2404 3530208 }
2405 else
2406 {
2407 3530208 checkflag = rpos_handle.sflag();
2408 }
2409
2410
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2411 {
2412
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2413 {
2414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2415 906 }
2416 else
2417 {
2418 192 checkflag = strike_hint;
2419 }
2420 1098 }
2421
2422
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2423 {
2424 case 0:
2425 case mfZELDA:
2426 case mfPUSHED:
2427 case mfENEMY0:
2428 case mfENEMY1:
2429 case mfENEMY2:
2430 case mfENEMY3:
2431 case mfENEMY4:
2432 case mfENEMY5:
2433 case mfENEMY6:
2434 case mfENEMY7:
2435 case mfENEMY8:
2436 case mfENEMY9:
2437 case mfSINGLE:
2438 case mfSINGLE16:
2439 case mfNOENEMY:
2440 case mfTRAP_H:
2441 case mfTRAP_V:
2442 case mfTRAP_4:
2443 case mfTRAP_LR:
2444 case mfTRAP_UD:
2445 case mfNOGROUNDENEMY:
2446 case mfNOBLOCKS:
2447 case mfSCRIPT1:
2448 case mfSCRIPT2:
2449 case mfSCRIPT3:
2450 case mfSCRIPT4:
2451 case mfSCRIPT5:
2452 case mfSCRIPT6:
2453 case mfSCRIPT7:
2454 case mfSCRIPT8:
2455 case mfSCRIPT9:
2456 case mfSCRIPT10:
2457 case mfSCRIPT11:
2458 case mfSCRIPT12:
2459 case mfSCRIPT13:
2460 case mfSCRIPT14:
2461 case mfSCRIPT15:
2462 case mfSCRIPT16:
2463 case mfSCRIPT17:
2464 case mfSCRIPT18:
2465 case mfSCRIPT19:
2466 case mfSCRIPT20:
2467 case mfPITHOLE:
2468 case mfPITFALLFLOOR:
2469 case mfLAVA:
2470 case mfICE:
2471 case mfICEDAMAGE:
2472 case mfDAMAGE1:
2473 case mfDAMAGE2:
2474 case mfDAMAGE4:
2475 case mfDAMAGE8:
2476 case mfDAMAGE16:
2477 case mfDAMAGE32:
2478 case mfFREEZEALL:
2479 case mfFREZEALLANSFFCS:
2480 case mfFREEZEFFCSOLY:
2481 case mfSCRITPTW1TRIG:
2482 case mfSCRITPTW2TRIG:
2483 case mfSCRITPTW3TRIG:
2484 case mfSCRITPTW4TRIG:
2485 case mfSCRITPTW5TRIG:
2486 case mfSCRITPTW6TRIG:
2487 case mfSCRITPTW7TRIG:
2488 case mfSCRITPTW8TRIG:
2489 case mfSCRITPTW9TRIG:
2490 case mfSCRITPTW10TRIG:
2491 case mfTROWEL:
2492 case mfTROWELNEXT:
2493 case mfTROWELSPECIALITEM:
2494 case mfSLASHPOT:
2495 case mfLIFTPOT:
2496 case mfLIFTORSLASH:
2497 case mfLIFTROCK:
2498 case mfLIFTROCKHEAVY:
2499 case mfDROPITEM:
2500 case mfSPECIALITEM:
2501 case mfDROPKEY:
2502 case mfDROPLKEY:
2503 case mfDROPCOMPASS:
2504 case mfDROPMAP:
2505 case mfDROPBOSSKEY:
2506 case mfSPAWNNPC:
2507 case mfSWITCHHOOK:
2508 case mfSIDEVIEWLADDER:
2509 case mfSIDEVIEWPLATFORM:
2510 case mfNOENEMYSPAWN:
2511 case mfENEMYALL:
2512 case mfNOMIRROR:
2513 case mfUNSAFEGROUND:
2514 case mf168:
2515 case mf169:
2516 case mf170:
2517 case mf171:
2518 case mf172:
2519 case mf173:
2520 case mf174:
2521 case mf175:
2522 case mf176:
2523 case mf177:
2524 case mf178:
2525 case mf179:
2526 case mf180:
2527 case mf181:
2528 case mf182:
2529 case mf183:
2530 case mf184:
2531 case mf185:
2532 case mf186:
2533 case mf187:
2534 case mf188:
2535 case mf189:
2536 case mf190:
2537 case mf191:
2538 case mf192:
2539 case mf193:
2540 case mf194:
2541 case mf195:
2542 case mf196:
2543 case mf197:
2544 case mf198:
2545 case mf199:
2546 case mf200:
2547 case mf201:
2548 case mf202:
2549 case mf203:
2550 case mf204:
2551 case mf205:
2552 case mf206:
2553 case mf207:
2554 case mf208:
2555 case mf209:
2556 case mf210:
2557 case mf211:
2558 case mf212:
2559 case mf213:
2560 case mf214:
2561 case mf215:
2562 case mf216:
2563 case mf217:
2564 case mf218:
2565 case mf219:
2566 case mf220:
2567 case mf221:
2568 case mf222:
2569 case mf223:
2570 case mf224:
2571 case mf225:
2572 case mf226:
2573 case mf227:
2574 case mf228:
2575 case mf229:
2576 case mf230:
2577 case mf231:
2578 case mf232:
2579 case mf233:
2580 case mf234:
2581 case mf235:
2582 case mf236:
2583 case mf237:
2584 case mf238:
2585 case mf239:
2586 case mf240:
2587 case mf241:
2588 case mf242:
2589 case mf243:
2590 case mf244:
2591 case mf245:
2592 case mf246:
2593 case mf247:
2594 case mf248:
2595 case mf249:
2596 case mf250:
2597 case mf251:
2598 case mf252:
2599 case mf253:
2600 case mf254:
2601 case mfEXTENDED:
2602 6911766 break;
2603
2604 case mfPUSHUD:
2605 case mfPUSHLR:
2606 case mfPUSH4:
2607 case mfPUSHU:
2608 case mfPUSHD:
2609 case mfPUSHL:
2610 case mfPUSHR:
2611 case mfPUSHUDNS:
2612 case mfPUSHLRNS:
2613 case mfPUSH4NS:
2614 case mfPUSHUNS:
2615 case mfPUSHDNS:
2616 case mfPUSHLNS:
2617 case mfPUSHRNS:
2618 case mfPUSHUDINS:
2619 case mfPUSHLRINS:
2620 case mfPUSH4INS:
2621 case mfPUSHUINS:
2622 case mfPUSHDINS:
2623 case mfPUSHLINS:
2624 case mfPUSHRINS:
2625
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2626
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2627 {
2628 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2629 }
2630
2631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2632
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2633 {
2634
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2635 {
2636
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2637 {
2638 case cPUSH_HEAVY:
2639 case cPUSH_HW:
2640 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2641 144 tempitemx=x, tempitemy=y;
2642
2643
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2644 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2645
2646 72 break;
2647
2648 case cPUSH_HEAVY2:
2649 case cPUSH_HW2:
2650 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2651 126 tempitemx=x, tempitemy=y;
2652
2653
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2654 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2655
2656 63 break;
2657 }
2658 1032 }
2659 2520 }
2660
2661 3258 break;
2662
2663 case mfWHISTLE:
2664
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2665 {
2666 tempitem=getItemID(itemsbuf,itype_whistle,1);
2667
2668 if(tempitem<0) break;
2669
2670 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2671 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2672 {
2673 tempitemx=x;
2674 tempitemy=y;
2675 }
2676
2677 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2678 }
2679
2680 2418 break;
2681
2682 //Why is this here?
2683 case mfFAIRY:
2684 case mfMAGICFAIRY:
2685 case mfALLFAIRY:
2686 if(hints)
2687 {
2688 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2689
2690 if(tempitem < 0) break;
2691
2692 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2693 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2694 {
2695 tempitemx=x;
2696 tempitemy=y;
2697 }
2698
2699 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2700 }
2701
2702 break;
2703
2704 case mfANYFIRE:
2705
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2706 {
2707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2708 252 }
2709 else
2710 {
2711 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2712
2713
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2714
2715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2716
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2717 {
2718 189 tempitemx=x;
2719 189 tempitemy=y;
2720 189 }
2721
2722 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2723 }
2724
2725 504 break;
2726
2727 case mfSTRONGFIRE:
2728 if(!hints)
2729 {
2730 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2731 }
2732 else
2733 {
2734 tempitem=getItemID(itemsbuf,itype_candle,2);
2735
2736 if(tempitem<0) break;
2737
2738 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2739 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2740 {
2741 tempitemx=x;
2742 tempitemy=y;
2743 }
2744
2745 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2746 }
2747
2748 break;
2749
2750 case mfMAGICFIRE:
2751 if(!hints)
2752 {
2753 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2754 }
2755 else
2756 {
2757 tempitem=getItemID(itemsbuf,itype_wand,1);
2758
2759 if(tempitem<0) break;
2760
2761 tempweapon=wFire;
2762
2763 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2764 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2765 {
2766 tempitemx=x;
2767 tempitemy=y;
2768 }
2769 else
2770 {
2771 tempweaponx=x;
2772 tempweapony=y;
2773 }
2774
2775 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2776 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2777 }
2778
2779 break;
2780
2781 case mfDIVINEFIRE:
2782 if(!hints)
2783 {
2784 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2785 }
2786 else
2787 {
2788 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2789
2790 if(tempitem<0) break;
2791
2792 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2793 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2794 {
2795 tempitemx=x;
2796 tempitemy=y;
2797 }
2798
2799 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2800 }
2801
2802 break;
2803
2804 case mfARROW:
2805
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2806 {
2807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2808 732 }
2809 else
2810 {
2811 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2812
2813
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2814
2815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2816
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2817 {
2818 61 tempitemx=x;
2819 61 tempitemy=y;
2820 61 }
2821
2822 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2823 }
2824
2825 814 break;
2826
2827 case mfSARROW:
2828 if(!hints)
2829 {
2830 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2831 }
2832 else
2833 {
2834 tempitem=getItemID(itemsbuf,itype_arrow,2);
2835
2836 if(tempitem<0) break;
2837
2838 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2839 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2840 {
2841 tempitemx=x;
2842 tempitemy=y;
2843 }
2844
2845 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2846 }
2847
2848 break;
2849
2850 case mfGARROW:
2851 if(!hints)
2852 {
2853 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2854 }
2855 else
2856 {
2857 tempitem=getItemID(itemsbuf,itype_arrow,3);
2858
2859 if(tempitem<0) break;
2860
2861 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2862 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2863 {
2864 tempitemx=x;
2865 tempitemy=y;
2866 }
2867
2868 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2869 }
2870
2871 break;
2872
2873 case mfBOMB:
2874
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2875 {
2876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2877 76 }
2878 else
2879 {
2880 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2881 17 tempweapon = wLitBomb;
2882
2883 //if (tempitem<0) break;
2884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2885
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2886 {
2887 12 tempweaponx=x;
2888 12 tempweapony=y;
2889 12 }
2890
2891 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2892 }
2893
2894 93 break;
2895
2896 case mfSBOMB:
2897
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2898 {
2899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2900 48 }
2901 else
2902 {
2903 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2904 //if (tempitem<0) break;
2905 48 tempweapon = wLitSBomb;
2906
2907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2908
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2909 {
2910 36 tempweaponx=x;
2911 36 tempweapony=y;
2912 36 }
2913
2914 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2915 }
2916
2917 96 break;
2918
2919 case mfARMOS_SECRET:
2920
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2921 {
2922
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2923 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2924 12 }
2925 24 break;
2926
2927 case mfBRANG:
2928
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2929 {
2930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2931 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2932 20 }
2933 else
2934 {
2935 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2936
2937
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2938
2939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2940
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2941 {
2942 4 tempitemx=x;
2943 4 tempitemy=y;
2944 4 }
2945
2946 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2947 }
2948
2949 25 break;
2950
2951 case mfMBRANG:
2952 if(!hints)
2953 {
2954 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2955 }
2956 else
2957 {
2958 tempitem=getItemID(itemsbuf,itype_brang,2);
2959
2960 if(tempitem<0) break;
2961
2962 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2963 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2964 {
2965 tempitemx=x;
2966 tempitemy=y;
2967 }
2968
2969 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2970 }
2971
2972 break;
2973
2974 case mfFBRANG:
2975 if(!hints)
2976 {
2977 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2978 }
2979 else
2980 {
2981 tempitem=getItemID(itemsbuf,itype_brang,3);
2982
2983 if(tempitem<0) break;
2984
2985 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2986 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2987 {
2988 tempitemx=x;
2989 tempitemy=y;
2990 }
2991
2992 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2993 }
2994
2995 break;
2996
2997 case mfWANDMAGIC:
2998
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
2999 {
3000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
3001 138 }
3002 else
3003 {
3004 tempitem=getItemID(itemsbuf,itype_wand,1);
3005
3006 if(tempitem<0) break;
3007
3008 tempweapon=itemsbuf[tempitem].wpn3;
3009
3010 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3011 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3012 {
3013 tempitemx=x;
3014 tempitemy=y;
3015 }
3016 else
3017 {
3018 tempweaponx=x;
3019 tempweapony=y;
3020 --lens_hint_weapon[wMagic][4];
3021
3022 if(lens_hint_weapon[wMagic][4]<-8)
3023 {
3024 lens_hint_weapon[wMagic][4]=8;
3025 }
3026 }
3027
3028 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3029 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3030 }
3031
3032 138 break;
3033
3034 case mfREFMAGIC:
3035
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3036 {
3037 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3038 }
3039 else
3040 {
3041 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3042
3043
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3044
3045 16 tempweapon=ewMagic;
3046
3047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3048
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3049 {
3050 13 tempitemx=x;
3051 13 tempitemy=y;
3052 13 }
3053 else
3054 {
3055 3 tempweaponx=x;
3056 3 tempweapony=y;
3057
3058
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3059 {
3060 1 --lens_hint_weapon[ewMagic][4];
3061 1 }
3062 else
3063 {
3064 2 ++lens_hint_weapon[ewMagic][4];
3065 }
3066
3067
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3068 {
3069 lens_hint_weapon[ewMagic][2]=up;
3070 }
3071
3072
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3073 {
3074 2 lens_hint_weapon[ewMagic][2]=down;
3075 2 }
3076 }
3077
3078 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3079 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3080 }
3081
3082 16 break;
3083
3084 case mfREFFIREBALL:
3085
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3086 {
3087 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3088 }
3089 else
3090 {
3091 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3092
3093
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3094
3095 16 tempweapon=ewFireball;
3096
3097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3098
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3099 {
3100 12 tempitemx=x;
3101 12 tempitemy=y;
3102 12 tempweaponx=x;
3103 12 tempweapony=y;
3104 12 ++lens_hint_weapon[ewFireball][3];
3105
3106
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3107 {
3108 1 lens_hint_weapon[ewFireball][3]=-8;
3109 1 lens_hint_weapon[ewFireball][4]=8;
3110 1 }
3111
3112
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3113 {
3114 8 ++lens_hint_weapon[ewFireball][4];
3115 8 }
3116 else
3117 {
3118 4 --lens_hint_weapon[ewFireball][4];
3119 }
3120 12 }
3121
3122 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3123 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3124 }
3125
3126 16 break;
3127
3128 case mfSWORD:
3129
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3130 {
3131 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3132 }
3133 else
3134 {
3135 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3136
3137
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3138
3139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3140
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3141 {
3142 5 tempitemx=x;
3143 5 tempitemy=y;
3144 5 }
3145
3146 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3147 }
3148
3149 7 break;
3150
3151 case mfWSWORD:
3152 if(!hints)
3153 {
3154 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3155 }
3156 else
3157 {
3158 tempitem=getItemID(itemsbuf,itype_sword,2);
3159
3160 if(tempitem<0) break;
3161
3162 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3163 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3164 {
3165 tempitemx=x;
3166 tempitemy=y;
3167 }
3168
3169 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3170 }
3171
3172 break;
3173
3174 case mfMSWORD:
3175 if(!hints)
3176 {
3177 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3178 }
3179 else
3180 {
3181 tempitem=getItemID(itemsbuf,itype_sword,3);
3182
3183 if(tempitem<0) break;
3184
3185 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3186 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3187 {
3188 tempitemx=x;
3189 tempitemy=y;
3190 }
3191
3192 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3193 }
3194
3195 break;
3196
3197 case mfXSWORD:
3198 if(!hints)
3199 {
3200 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3201 }
3202 else
3203 {
3204 tempitem=getItemID(itemsbuf,itype_sword,4);
3205
3206 if(tempitem<0) break;
3207
3208 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3209 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3210 {
3211 tempitemx=x;
3212 tempitemy=y;
3213 }
3214
3215 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3216 }
3217
3218 break;
3219
3220 case mfSWORDBEAM:
3221
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3222 {
3223 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3224 }
3225 else
3226 {
3227 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3228
3229
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3230
3231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3232
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3233 {
3234 11 tempitemx=x;
3235 11 tempitemy=y;
3236 11 }
3237
3238 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3239 }
3240
3241 16 break;
3242
3243 case mfWSWORDBEAM:
3244 if(!hints)
3245 {
3246 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3247 }
3248 else
3249 {
3250 tempitem=getItemID(itemsbuf,itype_sword,2);
3251
3252 if(tempitem<0) break;
3253
3254 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3255 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3256 {
3257 tempitemx=x;
3258 tempitemy=y;
3259 }
3260
3261 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3262 }
3263
3264 break;
3265
3266 case mfMSWORDBEAM:
3267 if(!hints)
3268 {
3269 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3270 }
3271 else
3272 {
3273 tempitem=getItemID(itemsbuf,itype_sword,3);
3274
3275 if(tempitem<0) break;
3276
3277 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3278 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3279 {
3280 tempitemx=x;
3281 tempitemy=y;
3282 }
3283
3284 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3285 }
3286
3287 break;
3288
3289 case mfXSWORDBEAM:
3290 if(!hints)
3291 {
3292 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3293 }
3294 else
3295 {
3296 tempitem=getItemID(itemsbuf,itype_sword,4);
3297
3298 if(tempitem<0) break;
3299
3300 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3301 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3302 {
3303 tempitemx=x;
3304 tempitemy=y;
3305 }
3306
3307 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3308 }
3309
3310 break;
3311
3312 case mfHOOKSHOT:
3313
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3314 {
3315 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3316 }
3317 else
3318 {
3319 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3320
3321
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3322
3323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3324
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3325 {
3326 12 tempitemx=x;
3327 12 tempitemy=y;
3328 12 }
3329
3330 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3331 }
3332
3333 17 break;
3334
3335 case mfWAND:
3336
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3337 {
3338 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3339 }
3340 else
3341 {
3342 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3343
3344
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3345
3346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3347
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3348 {
3349 28 tempitemx=x;
3350 28 tempitemy=y;
3351 28 }
3352
3353 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3354 }
3355
3356 35 break;
3357
3358 case mfHAMMER:
3359
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3360 {
3361 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3362 }
3363 else
3364 {
3365 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3366
3367
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3368
3369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3370
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3371 {
3372 13 tempitemx=x;
3373 13 tempitemy=y;
3374 13 }
3375
3376 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3377 }
3378
3379 17 break;
3380
3381 case mfARMOS_ITEM:
3382 case mfDIVE_ITEM:
3383 {
3384
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
2602 int flag = (cur_screen < 128 && get_qr(qr_ITEMPICKUPSETSBELOW)) ? mITEM : mSPECIALITEM;
3385
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, flag) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3386 {
3387 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3388 2602 }
3389 2602 break;
3390 }
3391
3392 case 16:
3393 case 17:
3394 case 18:
3395 case 19:
3396 case 20:
3397 case 21:
3398 case 22:
3399 case 23:
3400 case 24:
3401 case 25:
3402 case 26:
3403 case 27:
3404 case 28:
3405 case 29:
3406 case 30:
3407 case 31:
3408
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3410 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3411
3412 108898 break;
3413 case mfSECRETSNEXT:
3414 if(!hints)
3415 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3416 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3417
3418 break;
3419
3420 case mfSTRIKE:
3421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3422 {
3423 906 goto special;
3424 }
3425 else
3426 {
3427 break;
3428 }
3429
3430 28750 default: goto special;
3431
3432 special:
3433
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3434 {
3435
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3436 {
3437 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3438 4954 }
3439 6604 }
3440
3441 29656 break;
3442 }
3443 7060416 }
3444 3530208 });
3445
3446 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3447 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3448
3449 40116 offx -= viewport.x;
3450 40116 offy -= viewport.y;
3451 40116 offy += playing_field_offset;
3452
3453
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3454 {
3455
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3456 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3457
3458
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3459 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3460
3461
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3462 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3463
3464
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3465 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3466
3467
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3468 {
3469 129 showbombeddoor(scr, dest, 0, offx, offy);
3470 43 }
3471
3472
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3473 {
3474 117 showbombeddoor(scr, dest, 1, offx, offy);
3475 39 }
3476
3477
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3478 {
3479 18 showbombeddoor(scr, dest, 2, offx, offy);
3480 6 }
3481
3482
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3483 {
3484 111 showbombeddoor(scr, dest, 3, offx, offy);
3485 37 }
3486 10029 }
3487
3488
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3489 {
3490
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3491 {
3492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3493 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3494 1123 }
3495 else
3496 {
3497
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3498 {
3499 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3500 48 int32_t tempitemx=-16+offx;
3501 48 int32_t tempitemy=-16+offy-playing_field_offset;
3502
3503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3504
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3505 {
3506 48 tempitemx=scr->stairx+offx;
3507 48 tempitemy=scr->stairy+offy;
3508 24 }
3509
3510 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3511 48 }
3512 }
3513 2034 }
3514 20058 });
3515 }
3516 20058 }
3517
3518 9690 void draw_lens_over()
3519 {
3520 9690 int w = 288;
3521 9690 int h = 240;
3522
3523
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3524 static int32_t last_width = -1;
3525 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3526
3527 // Only redraw the circle if the size has changed
3528
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3529 {
3530 20 clear_to_color(lens_scr, BLACK);
3531 20 circlefill(lens_scr, w, h, width, 0);
3532 20 circle(lens_scr, w, h, width+2, 0);
3533 20 circle(lens_scr, w, h, width+5, 0);
3534 20 last_width=width;
3535 20 }
3536
3537 9690 masked_blit(lens_scr, framebuf, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3538 9690 do_primitives(framebuf, SPLAYER_LENS_OVER);
3539 9690 }
3540
3541 37078309 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3542 {
3543 37078309 BITMAP* bmp = *bmp_ptr;
3544
3/4
✓ Branch 0 taken 37078309 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37078303 times.
✓ Branch 3 taken 6 times.
37078309 if (bmp->w == w && bmp->h == h)
3545 37078303 return;
3546
3547 6 int depth = bitmap_color_depth(bmp);
3548 6 destroy_bitmap(bmp);
3549 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3550 37078309 }
3551
3552 31797 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3553 {
3554
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 31792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
31797 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3555 31797 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3556
3557 31797 clear_to_color(wavebuf, BLACK);
3558 31797 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3559
3560 int32_t ofs;
3561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31797 times.
31797 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3562
4/6
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
✓ Branch 4 taken 494 times.
✓ Branch 5 taken 31303 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3563 31797 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3564
2/4
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3565 31797 int32_t i=frame%amp2;
3566
3567
2/2
✓ Branch 0 taken 5341896 times.
✓ Branch 1 taken 31797 times.
5373693 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3568 {
3569
3/4
✓ Branch 0 taken 2670948 times.
✓ Branch 1 taken 2670948 times.
✓ Branch 2 taken 2670948 times.
✗ Branch 3 not taken.
5341896 if(j&1 && interpol)
3570 {
3571 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3572 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3573 }
3574 else
3575 {
3576 5341896 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3577 }
3578
3579
1/2
✓ Branch 0 taken 5341896 times.
✗ Branch 1 not taken.
5341896 if(ofs)
3580 {
3581
2/2
✓ Branch 0 taken 1367525376 times.
✓ Branch 1 taken 5341896 times.
1372867272 for(int32_t k=0; k<256; k++)
3582 {
3583 1367525376 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3584 1367525376 }
3585 5341896 }
3586 5341896 }
3587 31797 }
3588
3589 28272 void draw_fuzzy(int32_t fuzz)
3590 // draws from right half of scrollbuf to framebuf
3591 {
3592 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3593 byte *start, *si, *di;
3594
3595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28272 times.
28272 if(fuzz<1)
3596 fuzz = 1;
3597
3598 28272 xstep = 128%fuzz;
3599
3600
2/2
✓ Branch 0 taken 5890 times.
✓ Branch 1 taken 22382 times.
28272 if(xstep > 0)
3601 22382 xstep = fuzz-xstep;
3602
3603 28272 ystep = 112%fuzz;
3604
3605
2/2
✓ Branch 0 taken 8246 times.
✓ Branch 1 taken 20026 times.
28272 if(ystep > 0)
3606 20026 ystep = fuzz-ystep;
3607
3608 28272 firsty = 1;
3609
3610
2/2
✓ Branch 0 taken 28272 times.
✓ Branch 1 taken 1020148 times.
1048420 for(y=0; y<framebuf->h;)
3611 {
3612 1020148 start = &(scrollbuf_old->line[y][256]);
3613
3614
4/4
✓ Branch 0 taken 1006012 times.
✓ Branch 1 taken 6347064 times.
✓ Branch 2 taken 6332928 times.
✓ Branch 3 taken 1020148 times.
7353076 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3615 {
3616 6332928 si = start;
3617 6332928 di = &(framebuf->line[y+dy][0]);
3618 6332928 i = xstep;
3619 6332928 firstx = 1;
3620
3621
2/2
✓ Branch 0 taken 1621229568 times.
✓ Branch 1 taken 6332928 times.
1627562496 for(dx=0; dx<framebuf->w; dx++)
3622 {
3623 1621229568 *(di++) = *si;
3624
3625
2/2
✓ Branch 0 taken 1366065344 times.
✓ Branch 1 taken 255164224 times.
1621229568 if(++i >= fuzz)
3626 {
3627
2/2
✓ Branch 0 taken 248831296 times.
✓ Branch 1 taken 6332928 times.
255164224 if(!firstx)
3628 248831296 si += fuzz;
3629 else
3630 {
3631 6332928 si += fuzz-xstep;
3632 6332928 firstx = 0;
3633 }
3634
3635 255164224 i = 0;
3636 255164224 }
3637 1621229568 }
3638 6332928 }
3639
3640
2/2
✓ Branch 0 taken 991876 times.
✓ Branch 1 taken 28272 times.
1020148 if(!firsty)
3641 991876 y += fuzz;
3642 else
3643 {
3644 28272 y += ystep;
3645 28272 ystep = fuzz;
3646 28272 firsty = 0;
3647 }
3648 }
3649 28272 }
3650
3651 18523256 void updatescr(bool allowwavy)
3652 {
3653
4/6
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 18522942 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 314 times.
✓ Branch 4 taken 314 times.
✗ Branch 5 not taken.
18523256 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3654
4/6
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 18522942 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 314 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 314 times.
18523256 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3655 18523256 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3656 18523256 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3657
3658
2/2
✓ Branch 0 taken 18495155 times.
✓ Branch 1 taken 28101 times.
18523256 if(toogam)
3659 {
3660 28101 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3661 28101 }
3662
3663
1/2
✓ Branch 0 taken 18523256 times.
✗ Branch 1 not taken.
18523256 if(Showpal)
3664 dump_pal(framebuf);
3665
3666
2/2
✓ Branch 0 taken 18007493 times.
✓ Branch 1 taken 515763 times.
18523256 if(!Playing)
3667 515763 black_opening_count=0;
3668
3669
2/2
✓ Branch 0 taken 18354800 times.
✓ Branch 1 taken 168456 times.
18523256 if(black_opening_count<0) //shape is opening up
3670 {
3671 168456 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3672
3673
2/4
✓ Branch 0 taken 168456 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 168456 times.
168456 if(Advance||(!Paused))
3674 {
3675 168456 ++black_opening_count;
3676 168456 }
3677 168456 }
3678
2/2
✓ Branch 0 taken 18306026 times.
✓ Branch 1 taken 48774 times.
18354800 else if(black_opening_count>0) //shape is closing
3679 {
3680 48774 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3681
3682
2/4
✓ Branch 0 taken 48774 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48774 times.
48774 if(Advance||(!Paused))
3683 {
3684 48774 --black_opening_count;
3685 48774 }
3686 48774 }
3687
3688
3/4
✓ Branch 0 taken 18309317 times.
✓ Branch 1 taken 213939 times.
✓ Branch 2 taken 18309317 times.
✗ Branch 3 not taken.
18523256 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3689 {
3690 black_opening_shape = bosCIRCLE;
3691 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3692 refreshTints();
3693 refreshpal=true;
3694 }
3695
3696
2/2
✓ Branch 0 taken 17890333 times.
✓ Branch 1 taken 632923 times.
18523256 if(refreshpal)
3697 {
3698 632923 refreshpal=false;
3699 632923 RAMpal[253] = _RGB(0,0,0);
3700 632923 RAMpal[254] = _RGB(255,255,255);
3701 632923 hw_palette = &RAMpal;
3702 632923 update_hw_pal = true;
3703 632923 refresh_rgb_tables();
3704 632923 }
3705
3706 18523256 bool clearwavy = (wavy <= 0);
3707
3708
2/2
✓ Branch 0 taken 8341 times.
✓ Branch 1 taken 18514915 times.
18523256 if(wavy <= 0)
3709 {
3710 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3711 18514915 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3712 18514915 }
3713
3714 18523256 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3715
3716
6/6
✓ Branch 0 taken 32047 times.
✓ Branch 1 taken 18491209 times.
✓ Branch 2 taken 31925 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31797 times.
18523256 if(wavy && Playing && allowwavy)
3717 {
3718 31797 draw_wavy(framebuf, wavybuf, wavy,false);
3719 31797 }
3720
3721
2/2
✓ Branch 0 taken 18514915 times.
✓ Branch 1 taken 8341 times.
18523256 if(clearwavy)
3722 18514915 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3723
2/4
✓ Branch 0 taken 8341 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8341 times.
8341 else if(Playing && !Paused)
3724 8341 wavy--; // Wavy was set by a script. Decrement it.
3725
3726
3/4
✓ Branch 0 taken 18007493 times.
✓ Branch 1 taken 515763 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18007493 times.
18523256 if(Playing && !Paused)
3727 18007493 ++light_wave_clk;
3728
3729
6/6
✓ Branch 0 taken 18007493 times.
✓ Branch 1 taken 515763 times.
✓ Branch 2 taken 260343 times.
✓ Branch 3 taken 17747150 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 260325 times.
18523256 if(Playing && msg_active && !screenscrolling)
3730 {
3731
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260258 times.
260325 if(!(msg_bg_display_buf->clip))
3732 260258 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3733
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260258 times.
260325 if(!(msg_portrait_display_buf->clip))
3734 260258 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3735
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260258 times.
260325 if(!(msg_txt_display_buf->clip))
3736 260258 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3737 260325 }
3738
3739
3/4
✓ Branch 0 taken 18523256 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18329529 times.
✓ Branch 3 taken 193727 times.
18523256 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3740
3741
2/2
✓ Branch 0 taken 18334802 times.
✓ Branch 1 taken 188454 times.
18523256 if(nosubscr)
3742 {
3743 188454 clear_to_color(panorama, 0);
3744 188454 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3745 188454 }
3746
3747 //TODO: Optimize blit 'overcalls' -Gleeok
3748
2/2
✓ Branch 0 taken 188454 times.
✓ Branch 1 taken 18334802 times.
18523256 BITMAP *source = nosubscr ? panorama : wavybuf;
3749 18523256 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3750
3751 18523256 update_hw_screen();
3752 18523256 }
3753
3754 //----------------------------------------------------------------
3755
3756 static PALETTE syspal;
3757 int32_t onGUISnapshot()
3758 {
3759 char buf[200];
3760 int32_t num=0;
3761 do
3762 {
3763 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3764 }
3765 while(num<99999 && exists(buf));
3766
3767 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3768 InfoDialog("Error", "Failed to save snapshot").show();
3769
3770 return D_O_K;
3771 }
3772
3773 int32_t onNonGUISnapshot()
3774 {
3775 PALETTE temppal;
3776 get_palette(temppal);
3777 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3778
3779 char buf[200];
3780 int32_t num=0;
3781
3782 do
3783 {
3784 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3785 }
3786 while(num<99999 && exists(buf));
3787
3788 if (no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3789 {
3790 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3791 clear_to_color(b,0);
3792 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3793 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3794 destroy_bitmap(b);
3795 }
3796 else
3797 {
3798 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3799 }
3800
3801 return D_O_K;
3802 }
3803
3804 int32_t onSnapshot()
3805 {
3806 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3807 {
3808 onGUISnapshot();
3809 }
3810 else
3811 {
3812 onNonGUISnapshot();
3813 }
3814
3815 return D_O_K;
3816 }
3817
3818 int32_t onSaveMapPic()
3819 {
3820 char buf[200];
3821 int32_t num=0;
3822 BITMAP* _screen_draw_buffer = NULL;
3823 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3824
3825 do
3826 {
3827 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3828 }
3829 while(num<99999 && exists(buf));
3830
3831 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3832 clear_to_color(mappic, BLACK);
3833
3834 if(!mappic)
3835 {
3836 enter_sys_pal();
3837 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3838 exit_sys_pal();
3839 return D_O_K;;
3840 }
3841
3842 clear_to_color(_screen_draw_buffer, BLACK);
3843
3844 auto prev_viewport = viewport;
3845 viewport.x = 0;
3846 viewport.y = 0;
3847
3848 // draw the map
3849
3850 for(int32_t y=0; y<8; y++)
3851 {
3852 for(int32_t x=0; x<16; x++)
3853 {
3854 if (!displayOnMap(x, y))
3855 continue;
3856
3857 int screen = map_scr_xy_to_index(x, y);
3858 auto scrs = loadscr2(screen);
3859 mapscr* scr = &scrs[0];
3860 if (!scr->is_valid())
3861 continue;
3862
3863 screen_handles_t screen_handles;
3864 for (int i = 0; i <= 6; i++)
3865 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3866
3867 int xx = 0;
3868 int yy = -playing_field_offset;
3869
3870 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3871 {
3872 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3873 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3874 }
3875
3876 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3877 {
3878 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3879 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3880 }
3881
3882 if(lenscheck(scr,0))
3883 putscr(scr, _screen_draw_buffer, 0, 0);
3884 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3885 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3886 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3887
3888 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3889 {
3890 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3891 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3892 }
3893
3894 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3895 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3896 {
3897 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3898 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3899 {
3900 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3901 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3902 }
3903 }
3904
3905 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3906 {
3907 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3908 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3909 }
3910
3911 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3912 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3913 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3914 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3915 {
3916 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3917 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3918 }
3919 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3920 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3921 if(replay_version_check(40))
3922 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3923 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3924 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3925 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3926
3927 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3928 }
3929 }
3930
3931 viewport = prev_viewport;
3932 save_bitmap(buf,mappic,RAMpal);
3933 destroy_bitmap(mappic);
3934 destroy_bitmap(_screen_draw_buffer);
3935 return D_O_K;
3936 }
3937
3938 46 void f_Quit(int32_t type)
3939 {
3940
2/4
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
46 if(type==qQUIT && !Playing)
3941 return;
3942
3943 46 bool from_menu = is_sys_pal;
3944
3945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
3946 {
3947 46 music_pause();
3948 46 pause_all_sfx();
3949 46 sys_mouse();
3950 46 }
3951 46 enter_sys_pal();
3952 46 clear_keybuf();
3953
3954
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 13 times.
46 if (replay_version_check(0, 10))
3955 13 replay_poll();
3956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (replay_is_replaying())
3957 46 replay_peek_quit();
3958
3959
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if (!replay_is_replaying())
3960 switch(type)
3961 {
3962 case qQUIT:
3963 onQuit();
3964 break;
3965
3966 case qRESET:
3967 onReset();
3968 break;
3969
3970 case qEXIT:
3971 onExit();
3972 break;
3973 }
3974
3975
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(Quit)
3976 {
3977 46 kill_sfx();
3978 46 music_stop();
3979 46 exit_sys_pal();
3980 46 update_hw_screen();
3981 46 }
3982 else
3983 {
3984 exit_sys_pal();
3985 if(!from_menu)
3986 {
3987 music_resume();
3988 resume_all_sfx();
3989 }
3990 }
3991
3992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
3993 46 game_mouse();
3994 46 eat_buttons();
3995
3996 46 zc_readrawkey(KEY_ESC);
3997
3998 46 zc_readrawkey(KEY_ENTER);
3999 46 }
4000
4001 //----------------------------------------------------------------
4002
4003 int32_t onNoWalls()
4004 {
4005 cheats_enqueue(Cheat::Walls);
4006 return D_O_K;
4007 }
4008
4009 int32_t onIgnoreSideview()
4010 {
4011 cheats_enqueue(Cheat::IgnoreSideView);
4012 return D_O_K;
4013 }
4014
4015 18521867 int32_t input_idle(bool checkmouse)
4016 {
4017 static int32_t mx, my, mz, mb;
4018
4019
4/6
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4960214 times.
✓ Branch 3 taken 13561653 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4960214 times.
23482081 if(keypressed() || zc_key_pressed() ||
4020
4/8
✓ Branch 0 taken 4960214 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4960214 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4960214 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4960214 times.
✗ Branch 7 not taken.
4960214 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4021 {
4022 13561653 idle_count = 0;
4023
4024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13561653 times.
13561653 if(active_count < MAX_ACTIVE)
4025 {
4026 13561653 ++active_count;
4027 13561653 }
4028 13561653 }
4029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4960214 times.
4960214 else if(idle_count < MAX_IDLE)
4030 {
4031 4960214 ++idle_count;
4032 4960214 active_count = 0;
4033 4960214 }
4034
4035 18521867 mx = mouse_x;
4036 18521867 my = mouse_y;
4037 18521867 mz = mouse_z;
4038 18521867 mb = mouse_b;
4039
4040 18521867 return idle_count;
4041 }
4042
4043 int32_t onGoFast()
4044 {
4045 cheats_enqueue(Cheat::Fast);
4046 return D_O_K;
4047 }
4048
4049 int32_t onKillCheat()
4050 {
4051 cheats_enqueue(Cheat::Kill);
4052 return D_O_K;
4053 }
4054
4055 int32_t onSecretsCheat()
4056 {
4057 cheats_enqueue(Cheat::TrigSecrets);
4058 return D_O_K;
4059 }
4060 int32_t onSecretsCheatPerm()
4061 {
4062 cheats_enqueue(Cheat::TrigSecretsPerm);
4063 return D_O_K;
4064 }
4065
4066 int32_t onShowLayer0()
4067 {
4068 show_layers[0] = !show_layers[0];
4069 return D_O_K;
4070 }
4071 int32_t onShowLayer1()
4072 {
4073 show_layers[1] = !show_layers[1];
4074 return D_O_K;
4075 }
4076 int32_t onShowLayer2()
4077 {
4078 show_layers[2] = !show_layers[2];
4079 return D_O_K;
4080 }
4081 int32_t onShowLayer3()
4082 {
4083 show_layers[3] = !show_layers[3];
4084 return D_O_K;
4085 }
4086 int32_t onShowLayer4()
4087 {
4088 show_layers[4] = !show_layers[4];
4089 return D_O_K;
4090 }
4091 int32_t onShowLayer5()
4092 {
4093 show_layers[5] = !show_layers[5];
4094 return D_O_K;
4095 }
4096 int32_t onShowLayer6()
4097 {
4098 show_layers[6] = !show_layers[6];
4099 return D_O_K;
4100 }
4101 int32_t onShowLayerO()
4102 {
4103 show_layer_over=!show_layer_over;
4104 return D_O_K;
4105 }
4106 int32_t onShowLayerP()
4107 {
4108 show_layer_push=!show_layer_push;
4109 return D_O_K;
4110 }
4111 int32_t onShowLayerS()
4112 {
4113 show_sprites=!show_sprites;
4114 return D_O_K;
4115 }
4116 int32_t onShowLayerF()
4117 {
4118 show_ffcs=!show_ffcs;
4119 return D_O_K;
4120 }
4121 int32_t onShowLayerW()
4122 {
4123 show_walkflags=!show_walkflags;
4124 if(show_walkflags)
4125 show_effectflags = false;
4126 return D_O_K;
4127 }
4128 int32_t onShowLayerE()
4129 {
4130 show_effectflags=!show_effectflags;
4131 if(show_effectflags)
4132 show_walkflags = false;
4133 return D_O_K;
4134 }
4135 int32_t onShowFFScripts()
4136 {
4137 show_ff_scripts=!show_ff_scripts;
4138 return D_O_K;
4139 }
4140 int32_t onShowHitboxes()
4141 {
4142 show_hitboxes=!show_hitboxes;
4143 return D_O_K;
4144 }
4145 int32_t onShowInfoOpacity()
4146 {
4147 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4148 zc_set_config("zc","debug_info_opacity",info_opacity);
4149 return D_O_K;
4150 }
4151
4152 int32_t onLightSwitch()
4153 {
4154 cheats_enqueue(Cheat::Light);
4155 return D_O_K;
4156 }
4157
4158 int32_t onGoTo();
4159 int32_t onGoToComplete();
4160
4161 18521867 bool handle_close_btn_quit()
4162 {
4163
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(close_button_quit)
4164 {
4165 close_button_quit=false;
4166 f_Quit(qEXIT);
4167 }
4168 18521867 return (exiting_program = Quit==qEXIT);
4169 }
4170
4171 18521867 void syskeys()
4172 {
4173 18521867 update_system_keys();
4174
4175 int32_t oldtitle_version;
4176
4177 18521867 poll_joystick();
4178
4179 18521867 handle_close_btn_quit();
4180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18521867 times.
18521867 if(Quit == qEXIT) return;
4181
4182
2/10
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18521867 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18521867 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4183 {
4184 System();
4185 }
4186
4187 18521867 mouse_down=gui_mouse_b();
4188
4189
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(zc_read_system_key(KEY_F1))
4190 {
4191 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4192 {
4193 halt=!halt;
4194 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4195 }
4196 else
4197 {
4198 Throttlefps=!Throttlefps;
4199 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4200 }
4201 }
4202
4203
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(zc_read_system_key(KEY_F2))
4204 {
4205 ShowFPS=!ShowFPS;
4206 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4207 }
4208
4209
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18521867 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18521867 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4210
4211
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18521867 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18521867 if(zc_read_system_key(KEY_F4) && Playing)
4212 {
4213 Paused=true;
4214 Advance=true;
4215 }
4216
4217
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(zc_read_system_key(KEY_F6)) onTryQuit();
4218
4219 #ifndef ALLEGRO_MACOSX
4220
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4221
4222
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4223 #else
4224 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4225
4226 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4227 #endif
4228
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18521867 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18521867 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4229
4230
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if (zc_read_system_key(KEY_F12))
4231 {
4232 onSnapshot();
4233 }
4234
4235
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18521867 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18521867 if(debug_enabled && zc_read_system_key(KEY_TAB))
4236 set_debug(!get_debug());
4237
4238
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(CheatModifierKeys())
4239 {
4240 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4241 {
4242 if(!bindable_cheat(c))
4243 continue;
4244 if(get_debug() || cheat >= cheat_lvl(c))
4245 {
4246 if(checkcheat(c))
4247 cheats_hit_bind(c);
4248 }
4249 }
4250 }
4251
4252
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(volkeys)
4253 {
4254 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4255
4256 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4257
4258 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4259
4260 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4261 }
4262
4263
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18521867 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18521867 if(!get_debug() || !SystemKeys || replay_is_replaying())
4264 18521867 goto bottom;
4265
4266 if(zc_readkey(KEY_P)) Paused=!Paused;
4267
4268 if(zc_readkey(KEY_A))
4269 {
4270 Paused=true;
4271 Advance=true;
4272 }
4273
4274 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4275 #ifndef ALLEGRO_MACOSX
4276 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4277
4278 if(zc_readkey(KEY_F7))
4279 {
4280 Matrix(ss_speed, ss_density, 0);
4281 game_pal();
4282 }
4283 #else
4284 // The reason these are different on Mac in the first place is that
4285 // the OS doesn't let us use F9 and F10...
4286 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4287
4288 if(zc_readkey(KEY_F9))
4289 {
4290 Matrix(ss_speed, ss_density, 0);
4291 game_pal();
4292 }
4293 #endif
4294 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4295 {
4296 //change containers
4297 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4298 {
4299 //magic containers
4300 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4301 {
4302 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4303 }
4304 else
4305 {
4306 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4307 }
4308 }
4309 else
4310 {
4311 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4312 {
4313 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4314 }
4315 else
4316 {
4317 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4318 }
4319 }
4320 }
4321
4322 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4323 {
4324 //change containers
4325 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4326 {
4327 //magic containers
4328 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4329 {
4330 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4331 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4332 //heart containers
4333 }
4334 else
4335 {
4336 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4337 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4338 }
4339 }
4340 else
4341 {
4342 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4343 {
4344 game->set_magic(zc_max(game->get_magic()-1,0));
4345 }
4346 else
4347 {
4348 game->set_life(zc_max(game->get_life()-1,0));
4349 }
4350 }
4351 }
4352
4353 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4354
4355 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4356
4357 verifyBothWeapons();
4358
4359 bottom:
4360
4361
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(input_idle(true) > after_time())
4362 {
4363 Matrix(ss_speed, ss_density, 0);
4364 game_pal();
4365 }
4366 18521867 }
4367
4368 5967361 void checkQuitKeys()
4369 {
4370 #ifndef ALLEGRO_MACOSX
4371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5967361 times.
5967361 if(key[KEY_F9]) f_Quit(qRESET);
4372
4373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5967361 times.
5967361 if(key[KEY_F10]) f_Quit(qEXIT);
4374 #else
4375 if(key[KEY_F7]) f_Quit(qRESET);
4376
4377 if(key[KEY_F8]) f_Quit(qEXIT);
4378 #endif
4379 5967361 }
4380
4381 18522067 bool CheatModifierKeys()
4382 {
4383 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4384 // to trigger cheats.
4385
2/2
✓ Branch 0 taken 18521767 times.
✓ Branch 1 taken 300 times.
18522067 if (replay_is_replaying())
4386 18521767 return false;
4387
4388
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4389
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4391 {
4392
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4393 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4394 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4395 {
4396 return true;
4397 }
4398 }
4399 100 return false;
4400 18521867 }
4401
4402 //99:05:54, for some reason?
4403 #define OLDMAXTIME 21405240
4404 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4405 #define MAXTIME 1944000000
4406
4407 // (qr, value)
4408 411 static std::queue<std::pair<int, bool>> change_qr_queue;
4409
4410 7 void enqueue_qr_change(int qr, bool value)
4411 {
4412 7 change_qr_queue.push({qr, value});
4413 7 }
4414
4415 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4416 // and soon executed here.
4417 // During playing back a replay file, the replay system adds to the same queue and
4418 // is executed here too.
4419 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4420 // could be later extended to all QRs (perhaps as a cheat).
4421 18522290 void process_enqueued_qr_changes()
4422 {
4423
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 18522189 times.
18522290 if (replay_is_replaying())
4424 18522189 replay_do_qrs();
4425
4426
2/2
✓ Branch 0 taken 18522290 times.
✓ Branch 1 taken 7 times.
18522297 while (!change_qr_queue.empty())
4427 {
4428 28 auto [qr, value] = change_qr_queue.front();
4429 7 change_qr_queue.pop();
4430
4431 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4432 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4433 14 _qrs_unpacked[qr] = value;
4434 7 apply_qr_rule(qr);
4435
4436
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4437 2 replay_step_qr(qr, value);
4438 }
4439 18522290 }
4440
4441 18523256 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4442 {
4443
1/2
✓ Branch 0 taken 18523256 times.
✗ Branch 1 not taken.
18523256 if(zcmusic!=NULL)
4444 {
4445 zcmusic_poll();
4446 }
4447 18523256 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4448
4449 18523256 updatescr(allowwavy);
4450
4451 18523256 Advance=false;
4452
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18523256 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18523256 times.
18523256 while(Paused && !Advance && !Quit)
4453 {
4454 // have to call this, otherwise we'll get an infinite loop
4455 syskeys();
4456 if(allowF6Script)
4457 {
4458 FFCore.runF6Engine();
4459 }
4460
4461 #ifdef _WIN32
4462
4463 if(use_dwm_flush)
4464 {
4465 do_DwmFlush();
4466 }
4467
4468 #endif
4469
4470 // to keep music playing
4471 if(zcmusic!=NULL)
4472 {
4473 zcmusic_poll();
4474 }
4475
4476 update_hw_screen();
4477 }
4478
4479
2/2
✓ Branch 0 taken 18521904 times.
✓ Branch 1 taken 1352 times.
18523256 if(Quit)
4480 1352 return;
4481
4482
3/4
✓ Branch 0 taken 18006453 times.
✓ Branch 1 taken 515451 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18006453 times.
18521904 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4483 18006453 game->change_time(1);
4484
4485 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4486
4487 18521904 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4488
2/2
✓ Branch 0 taken 8722289 times.
✓ Branch 1 taken 9799615 times.
18521904 if (replay_version_check(0, 16))
4489 9799615 should_reset_down_state = replay_version_check(11, 16);
4490
2/2
✓ Branch 0 taken 15090560 times.
✓ Branch 1 taken 3431344 times.
18521904 if (should_reset_down_state)
4491 {
4492
2/2
✓ Branch 0 taken 61764192 times.
✓ Branch 1 taken 3431344 times.
65195536 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4493 61764192 down_control_states[i] = raw_control_state[i];
4494 3431344 }
4495
4496
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 18521867 times.
18521904 if (replay_is_active())
4497 {
4498
2/2
✓ Branch 0 taken 1545420 times.
✓ Branch 1 taken 16976447 times.
18521867 if (replay_version_check(3))
4499 16976447 replay_poll();
4500
4501
4/4
✓ Branch 0 taken 7478911 times.
✓ Branch 1 taken 11042956 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7378376 times.
18521867 if (replay_version_check(11) || replay_version_check(6, 8))
4502 11143491 replay_peek_input();
4503 18521867 }
4504
4505 18521904 process_enqueued_qr_changes();
4506
4507 18521904 load_control_called_this_frame = false;
4508
4509 18521904 poll_keyboard();
4510 18521904 update_keys();
4511
4512 18521904 ++frame;
4513
4514
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 18521767 times.
18521904 if (replay_is_replaying())
4515 18521767 replay_do_cheats();
4516 18521904 syskeys();
4517
4518 // The mouse variables can change from the mouse thread at anytime during a frame,
4519 // so save the result at the start so that replaying is consistent.
4520 18521904 script_mouse_x = gui_mouse_x();
4521 18521904 script_mouse_y = gui_mouse_y();
4522 18521904 script_mouse_z = mouse_z;
4523 18521904 script_mouse_b = mouse_b;
4524
4525 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4526 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4527 // approach here means it doesn't matter which call adds the cheat.
4528 18521904 cheats_execute_queued();
4529
4530
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 18521767 times.
18521904 if (replay_is_replaying())
4531 18521767 replay_peek_quit();
4532
2/2
✓ Branch 0 taken 18521858 times.
✓ Branch 1 taken 46 times.
18521904 if (GameFlags & GAMEFLAG_TRYQUIT)
4533 46 replay_step_quit(0);
4534
2/2
✓ Branch 0 taken 3322 times.
✓ Branch 1 taken 18518582 times.
18521904 if(allowF6Script)
4535 18518582 FFCore.runF6Engine();
4536
2/2
✓ Branch 0 taken 754 times.
✓ Branch 1 taken 18521150 times.
18521904 if (Quit)
4537 754 replay_step_quit(Quit);
4538
4539 #ifdef _WIN32
4540
4541 if(use_dwm_flush)
4542 {
4543 do_DwmFlush();
4544 }
4545
4546 #endif
4547
4548
2/2
✓ Branch 0 taken 208645 times.
✓ Branch 1 taken 18313259 times.
18521904 if(sfxcleanup)
4549 18313259 sfx_cleanup();
4550
4551 18521904 jit_poll();
4552
4553 #ifdef __EMSCRIPTEN__
4554 // Yield the main thread back to the browser occasionally.
4555 if (is_headless())
4556 {
4557 static int rate = 10000;
4558 static int force_yield = rate;
4559 if (force_yield++ >= rate)
4560 {
4561 force_yield = 0;
4562 emscripten_sleep(0);
4563 }
4564 }
4565 #endif
4566
4567
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18521804 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18521904 if (zqtesting_mode && test_mode_auto_restart)
4568 {
4569 static auto last_write_time = fs::last_write_time(qstpath);
4570 static auto last_check = std::chrono::system_clock::now();
4571
4572 if (std::chrono::system_clock::now() - last_check > 200ms)
4573 {
4574 last_check = std::chrono::system_clock::now();
4575 auto write_time = fs::last_write_time(qstpath);
4576 if (last_write_time != write_time)
4577 {
4578 last_write_time = write_time;
4579 disableClickToFreeze = false;
4580 Quit = qRESET;
4581 replay_quit();
4582 }
4583 }
4584 }
4585 18523256 }
4586
4587 590 void zapout()
4588 {
4589 590 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4590 590 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4591
4592 590 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4593 590 script_drawing_commands.Clear();
4594
4595 // zap out
4596
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 14160 times.
14750 for(int32_t i=1; i<=24; i++)
4597 {
4598 14160 draw_fuzzy(i);
4599 14160 advanceframe(true);
4600
4601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14160 times.
14160 if(Quit)
4602 {
4603 break;
4604 }
4605 14160 }
4606 590 }
4607
4608 588 void zapin()
4609 {
4610 588 FFCore.warpScriptCheck();
4611 588 draw_screen();
4612 588 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4613 588 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4614
4615 // zap out
4616 588 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4617
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 14112 times.
14700 for(int32_t i=24; i>=1; i--)
4618 {
4619 14112 draw_fuzzy(i);
4620 14112 advanceframe(true);
4621
4622
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14112 times.
14112 if(Quit)
4623 {
4624 break;
4625 }
4626 14112 }
4627 588 }
4628
4629
4630 235 void wavyout(bool showhero)
4631 {
4632 235 draw_screen(showhero);
4633
4634 235 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4635 235 clear_to_color(wavebuf,0);
4636 235 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4637
4638 static PALETTE wavepal;
4639
4640 int32_t ofs;
4641 235 int32_t amplitude=8;
4642
4643 235 int32_t wavelength=4;
4644 235 int height = viewport.visible_height(show_bottom_8px);
4645 235 double palpos=0, palstep=4, palstop=126;
4646
4647 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4648
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<height; i+=wavelength)
4649 {
4650
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4651 {
4652 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4653 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4654 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4655 2520320 }
4656
4657 9845 palpos+=palstep;
4658
4659
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4660 {
4661 9845 hw_palette = &wavepal;
4662 9845 update_hw_pal = true;
4663 9845 }
4664 else
4665 {
4666 hw_palette = &RAMpal;
4667 update_hw_pal = true;
4668 }
4669
4670
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4671 {
4672
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4673 {
4674 423413760 ofs=0;
4675
4676
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4677 {
4678 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4679 103224320 }
4680
4681 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4682 423413760 }
4683 1653960 }
4684
4685 9845 advanceframe(true);
4686
4687
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4688 1 break;
4689 9844 }
4690
4691 235 destroy_bitmap(wavebuf);
4692
4693 235 hw_palette = &RAMpal;
4694 235 update_hw_pal = true;
4695 235 }
4696
4697 232 void wavyin()
4698 {
4699 232 draw_screen();
4700
4701 232 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4702 232 clear_to_color(wavebuf,0);
4703 232 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4704
4705 static PALETTE wavepal;
4706
4707 232 refreshpal=false;
4708 int32_t ofs;
4709 232 int32_t amplitude=8;
4710 232 int32_t wavelength=4;
4711 232 int height = viewport.visible_height(show_bottom_8px);
4712 232 double palpos=height, palstep=4, palstop=126;
4713
4714 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4715
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<height; i+=wavelength)
4716 {
4717
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4718 {
4719 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4720 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4721 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4722 2483968 }
4723
4724 9703 palpos-=palstep;
4725
4726
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4727 {
4728 9703 hw_palette = &wavepal;
4729 9703 update_hw_pal = true;
4730 9703 }
4731 else
4732 {
4733 hw_palette = &RAMpal;
4734 update_hw_pal = true;
4735 }
4736
4737
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4738 {
4739
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4740 {
4741 417306624 ofs=0;
4742
4743
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(height-1-i))&&(j&1))
4744 {
4745 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4746 104337152 }
4747
4748 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4749 417306624 }
4750 1630104 }
4751
4752 9703 advanceframe(true);
4753
4754
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4755 1 break;
4756 9702 }
4757
4758 232 destroy_bitmap(wavebuf);
4759
4760 232 hw_palette = &RAMpal;
4761 232 update_hw_pal = true;
4762 232 }
4763
4764 4344 void blackscr(int32_t fcnt,bool showsubscr)
4765 {
4766 4344 reset_pal_cycling();
4767 4344 script_drawing_commands.Clear();
4768
4769 4344 FFCore.warpScriptCheck();
4770 4344 bool showtime = game->should_show_time();
4771
2/2
✓ Branch 0 taken 4337 times.
✓ Branch 1 taken 129877 times.
134214 while(fcnt>0)
4772 {
4773 129877 clear_bitmap(framebuf);
4774
4775
2/2
✓ Branch 0 taken 59310 times.
✓ Branch 1 taken 70567 times.
129877 if(showsubscr)
4776 {
4777 70567 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4778
3/4
✓ Branch 0 taken 70567 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1350 times.
✓ Branch 3 taken 69217 times.
70567 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4779 {
4780 1350 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4781 1350 }
4782 70567 }
4783
4784 129877 advanceframe(true);
4785
4786
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129870 times.
129877 if(Quit)
4787 7 break;
4788
4789 129870 --fcnt;
4790 }
4791 4344 }
4792
4793 2738 void openscreen(int32_t shape)
4794 {
4795 2738 update_viewport();
4796 2738 is_opening_screen = true;
4797 2738 reset_pal_cycling();
4798 2738 black_opening_count=0;
4799
4800
3/4
✓ Branch 0 taken 530 times.
✓ Branch 1 taken 2208 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 530 times.
2738 if(COOLSCROLL || shape>-1)
4801 {
4802 2208 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4803 2208 return;
4804 }
4805 else
4806 {
4807 530 Hero.setDontDraw(true);
4808 530 show_subscreen_dmap_dots=false;
4809 530 show_subscreen_numbers=false;
4810 530 show_subscreen_life=false;
4811 }
4812
4813 530 int32_t x=128;
4814
4815 530 FFCore.warpScriptCheck();
4816
2/2
✓ Branch 0 taken 530 times.
✓ Branch 1 taken 42400 times.
42930 for(int32_t i=0; i<80; i++)
4817 {
4818 42400 draw_screen();
4819 42400 x=128-(((i*128/80)/8)*8);
4820
4821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42400 times.
42400 if(x>0)
4822 {
4823 42400 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4824 42400 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4825 42400 }
4826
4827 42400 advanceframe(true);
4828
4829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42400 times.
42400 if(Quit)
4830 {
4831 break;
4832 }
4833 42400 }
4834
4835 530 Hero.setDontDraw(false);
4836 530 show_subscreen_items=true;
4837 530 show_subscreen_dmap_dots=true;
4838 530 show_subscreen_numbers=true;
4839 530 show_subscreen_life=true;
4840 2738 }
4841
4842 14 void closescreen(int32_t shape)
4843 {
4844 14 is_opening_screen = false;
4845 14 reset_pal_cycling();
4846 14 black_opening_count=0;
4847
4848
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(COOLSCROLL || shape>-1)
4849 {
4850 14 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4851 14 return;
4852 }
4853 else
4854 {
4855 Hero.setDontDraw(true);
4856 show_subscreen_dmap_dots=false;
4857 show_subscreen_numbers=false;
4858 // show_subscreen_items=false;
4859 show_subscreen_life=false;
4860 }
4861
4862 int32_t x=128;
4863
4864 FFCore.warpScriptCheck();
4865 for(int32_t i=79; i>=0; --i)
4866 {
4867 draw_screen();
4868 x=128-(((i*128/80)/8)*8);
4869
4870 if(x>0)
4871 {
4872 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4873 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4874 }
4875
4876 advanceframe(true);
4877
4878 if(Quit)
4879 {
4880 break;
4881 }
4882 }
4883
4884 Hero.setDontDraw(false);
4885 show_subscreen_items=true;
4886 show_subscreen_dmap_dots=true;
4887 14 }
4888
4889 324 int32_t TriforceCount()
4890 {
4891 324 int32_t c=0;
4892
4893
2/2
✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 324 times.
2916 for(int32_t i=1; i<=8; i++)
4894
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 2108 times.
4700 if(game->lvlitems[i]&liTRIFORCE)
4895 2108 ++c;
4896
4897 324 return c;
4898 }
4899
4900 int32_t onCustomGame()
4901 {
4902 auto save = get_unset_save_slot();
4903 if (!save)
4904 return D_CLOSE;
4905
4906 if (prompt_for_quest_path(save->header->qstpath))
4907 {
4908 save->header->qstpath = qstpath;
4909 return D_O_K;
4910 }
4911
4912 return D_CLOSE;
4913 }
4914
4915 int32_t onContinue()
4916 {
4917 return D_CLOSE;
4918 }
4919
4920 int32_t onThrottleFPS()
4921 {
4922 Throttlefps = !Throttlefps;
4923 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4924 return D_O_K;
4925 }
4926
4927 int32_t onWinPosSave()
4928 {
4929 SaveWinPos = !SaveWinPos;
4930 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4931 return D_O_K;
4932 }
4933 int32_t onIntegerScaling()
4934 {
4935 scaleForceInteger = !scaleForceInteger;
4936 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4937 return D_O_K;
4938 }
4939 int32_t onStretchGame()
4940 {
4941 stretchGame = !stretchGame;
4942 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4943 return D_O_K;
4944 }
4945
4946 int32_t onClickToFreeze()
4947 {
4948 ClickToFreeze = !ClickToFreeze;
4949 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4950 return D_O_K;
4951 }
4952
4953 int32_t OnSaveZCConfig()
4954 {
4955 if(jwin_alert3(
4956 "Save Configuration",
4957 "Are you sure that you wish to save your present configuration settings?",
4958 "This will overwrite your prior settings!",
4959 NULL,
4960 "&Yes",
4961 "&No",
4962 NULL,
4963 'y',
4964 'n',
4965 0,
4966 get_zc_font(font_lfont)) == 1)
4967 {
4968 save_game_configs();
4969 return D_O_K;
4970 }
4971 else return D_O_K;
4972 }
4973
4974 int32_t OnnClearQuestDir()
4975 {
4976 auto current_path = fs::current_path() / "quests";
4977 if(jwin_alert3(
4978 "Clear Current Directory Cache",
4979 "Are you sure that you wish to reset where ZC Player looks for quests?",
4980 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4981 NULL,
4982 "&Yes",
4983 "&No",
4984 NULL,
4985 'y',
4986 'n',
4987 0,
4988 get_zc_font(font_lfont)) == 1)
4989 {
4990 zc_set_config("zeldadx","quest_dir","quests");
4991 flush_config_file();
4992 strcpy(qstdir,"quests");
4993 #ifdef __EMSCRIPTEN__
4994 em_sync_fs();
4995 #endif
4996 return D_O_K;
4997 }
4998 else return D_O_K;
4999 }
5000
5001 int32_t onConsole()
5002 {
5003 if ( !console_enabled )
5004 {
5005 AlertDialog("ZC Console",
5006 "Open the ZC Console?"
5007 "\nThis will display any messages logged by scripts,"
5008 " including errors.",
5009 [&](bool ret,bool)
5010 {
5011 if(ret)
5012 {
5013 FFCore.ZScriptConsole(true);
5014 }
5015 }).show();
5016 return D_O_K;
5017 }
5018 else
5019 {
5020 FFCore.ZScriptConsole(false);
5021 return D_O_K;
5022 }
5023 }
5024
5025 int32_t onClrConsoleOnReload()
5026 {
5027 clearConsoleOnReload = !clearConsoleOnReload;
5028 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5029 return D_O_K;
5030 }
5031 int32_t onClrConsoleOnLoad()
5032 {
5033 clearConsoleOnLoad = !clearConsoleOnLoad;
5034 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5035 return D_O_K;
5036 }
5037
5038
5039 int32_t onFrameSkip()
5040 {
5041 FrameSkip = !FrameSkip;
5042 return D_O_K;
5043 }
5044
5045 int32_t onSaveDragResize()
5046 {
5047 SaveDragResize = !SaveDragResize;
5048 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5049 return D_O_K;
5050 }
5051
5052 int32_t onDragAspect()
5053 {
5054 DragAspect = !DragAspect;
5055 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5056 return D_O_K;
5057 }
5058
5059 int32_t onTransLayers()
5060 {
5061 TransLayers = !TransLayers;
5062 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5063 return D_O_K;
5064 }
5065
5066 int32_t onNESquit()
5067 {
5068 NESquit = !NESquit;
5069 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5070 return D_O_K;
5071 }
5072
5073 int32_t onVolKeys()
5074 {
5075 volkeys = !volkeys;
5076 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5077 return D_O_K;
5078 }
5079
5080 int32_t onShowFPS()
5081 {
5082 ShowFPS = !ShowFPS;
5083 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5084 return D_O_K;
5085 }
5086
5087 int32_t onShowTime()
5088 {
5089 ShowGameTime = !ShowGameTime;
5090 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5091 return D_O_K;
5092 }
5093
5094 2185580306 bool is_Fkey(int32_t k)
5095 {
5096
2/2
✓ Branch 0 taken 222262404 times.
✓ Branch 1 taken 1963317902 times.
2185580306 switch(k)
5097 {
5098 case KEY_F1:
5099 case KEY_F2:
5100 case KEY_F3:
5101 case KEY_F4:
5102 case KEY_F5:
5103 case KEY_F6:
5104 case KEY_F7:
5105 case KEY_F8:
5106 case KEY_F9:
5107 case KEY_F10:
5108 case KEY_F11:
5109 case KEY_F12:
5110 222262404 return true;
5111 }
5112
5113 1963317902 return false;
5114 2185580306 }
5115
5116 void kb_getkey(DIALOG *d);
5117
5118 //Used by all keyboard key settings dialogues.
5119 void kb_clearjoystick(DIALOG *d)
5120 {
5121 d->flags|=D_SELECTED;
5122
5123 jwin_button_proc(MSG_DRAW,d,0);
5124 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5125 // text_mode(vc(11));
5126 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5127 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5128
5129 update_hw_screen();
5130
5131 clear_keybuf();
5132 int32_t k = next_press_key();
5133 clear_keybuf();
5134
5135 //shnarf
5136 //47=f1
5137 //59=esc
5138 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5139 // *((int32_t*)d->dp3) = k;
5140 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5141
5142
5143 d->flags&=~D_SELECTED;
5144 }
5145
5146 //Clears key to 0.
5147 //Used by all keyboard key settings dialogues.
5148 void kb_clearkey(DIALOG *d);
5149
5150 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5151 {
5152 switch(msg)
5153 {
5154 case MSG_KEY:
5155 case MSG_CLICK:
5156
5157 kb_clearjoystick(d);
5158
5159 while(gui_mouse_b())
5160 {
5161 clear_keybuf();
5162 rest(1);
5163 }
5164
5165 return D_REDRAW;
5166 }
5167
5168 return jwin_button_proc(msg,d,c);
5169 }
5170
5171 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5172 //Only used in keyboard settings dialogues to clear keys.
5173 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5174
5175 int32_t j_getbtn(DIALOG *d)
5176 {
5177 d->flags|=D_SELECTED;
5178 jwin_button_proc(MSG_DRAW,d,0);
5179 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5180 // text_mode(vc(11));
5181 int32_t y = screen->h/2 - 12;
5182 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5183 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5184 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5185
5186 update_hw_screen();
5187
5188 int32_t b = next_joy_input(true);
5189 if (b == -2)
5190 return D_CLOSE;
5191
5192 if(b>=0)
5193 *((int32_t*)d->dp3) = b;
5194
5195 d->flags&=~D_SELECTED;
5196
5197 return D_O_K;
5198 }
5199
5200 void j_getstick(DIALOG *d)
5201 {
5202 d->flags|=D_SELECTED;
5203 jwin_button_proc(MSG_DRAW,d,0);
5204 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5205 // text_mode(vc(11));
5206 int32_t y = screen->h/2 - 12;
5207 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5208 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5209 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5210
5211 update_hw_screen();
5212
5213 int32_t b = next_joy_input(false);
5214
5215 if(b>=0)
5216 *((int32_t*)d->dp3) = b;
5217
5218 d->flags&=~D_SELECTED;
5219 }
5220
5221 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5222 {
5223 switch(msg)
5224 {
5225 case MSG_KEY:
5226 case MSG_CLICK:
5227
5228 int ret = j_getbtn(d);
5229 if (ret != D_O_K)
5230 return ret;
5231
5232 while(gui_mouse_b()) {
5233 rest(1);
5234 clear_keybuf();
5235 }
5236
5237 return D_REDRAW;
5238 }
5239
5240 return jwin_button_proc(msg,d,c);
5241 }
5242
5243 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5244 {
5245 switch(msg)
5246 {
5247 case MSG_KEY:
5248 case MSG_CLICK:
5249
5250 j_getstick(d);
5251
5252 while(gui_mouse_b()) {
5253 rest(1);
5254 clear_keybuf();
5255 }
5256
5257 return D_REDRAW;
5258 }
5259
5260 return jwin_button_proc(msg,d,c);
5261 }
5262
5263 //shnarf
5264 extern const char *key_str[];
5265 std::string get_keystr(int key);
5266
5267 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5268
5269 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5270 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5271 str_primary_stick[80], str_secondary_stick[80];
5272
5273 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5274 {
5275 //these are here to bypass compiler warnings about unused arguments
5276 c=c;
5277
5278 if (d->w == 1)
5279 {
5280 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5281 {
5282 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5283 return D_CLOSE;
5284 }
5285 }
5286
5287 if(msg==MSG_DRAW)
5288 {
5289 switch(d->w)
5290 {
5291 case 0:
5292 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5293 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5294 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5295 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5296 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5297 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5298 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5299 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5300 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5301 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5302 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5303 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5304 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5305 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5306 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5307 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5308 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5309 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5310 break;
5311
5312 case 1:
5313 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5314 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5315 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5316 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5317 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5318 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5319 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5320 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5321 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5322 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5323 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5324 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5325 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5326 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5327 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5328 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5329 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5330 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5331 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5332 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5333 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5334 break;
5335
5336 case 2:
5337 sprintf(str_a," %3d",midi_volume);
5338 sprintf(str_l," %3d",emusic_volume);
5339 sprintf(str_r," %3d",sfx_volume);
5340 strcpy(str_s,pan_str[pan_style]);
5341 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5342 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5343 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5344 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5345 break;
5346 }
5347 }
5348
5349 return D_O_K;
5350 }
5351
5352 int32_t set_vol(void *dp3, int32_t d2)
5353 {
5354 switch(((int32_t*)dp3)[0])
5355 {
5356 case 0:
5357 midi_volume = zc_min(d2<<3,255);
5358 break;
5359
5360 case 1:
5361 digi_volume = zc_min(d2<<3,255);
5362 break;
5363
5364 case 2:
5365 emusic_volume = zc_min(d2<<3,255);
5366 break;
5367
5368 case 3:
5369 sfx_volume = zc_min(d2<<3,255);
5370 break;
5371 }
5372
5373 // text_mode(vc(11));
5374 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5375 return D_O_K;
5376 }
5377
5378 int32_t set_pan(void *dp3, int32_t d2)
5379 {
5380 pan_style = vbound(d2,0,3);
5381 // text_mode(vc(11));
5382 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5383 return D_O_K;
5384 }
5385
5386 static int32_t gamepad_joys_list[] =
5387 {
5388 61,
5389 -1
5390 };
5391
5392 static int32_t gamepad_btn_list[] =
5393 {
5394 6,
5395 7,8,9,10,11,12,13,14,15,16,17,
5396 18,19,20,21,22,23,24,25,26,27,28,
5397 29,30,31,32,33,34,35,36,37,38,39,
5398 -1
5399 };
5400
5401 static int32_t gamepad_dirs_list[] =
5402 {
5403 40,41,42,43,
5404 44,45,46,47,
5405 48,49,50,51,
5406 52,53,54,55,
5407 56,57,58,59,
5408 60,
5409 -1
5410 };
5411
5412 static TABPANEL gamepad_tabs[] =
5413 {
5414 // (text)
5415 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5416 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5417 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5418 { NULL, 0, NULL, 0, NULL }
5419 };
5420
5421 const char *joy_list(int32_t index, int32_t *list_size)
5422 {
5423 if (index == -1)
5424 {
5425 *list_size = al_get_num_joysticks();
5426 return NULL;
5427 }
5428
5429 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5430 if (!joy)
5431 {
5432 return "?";
5433 }
5434
5435 return al_get_joystick_name(joy);
5436 }
5437
5438 411 static ListData joy__list(joy_list, &font);
5439
5440 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5441 {
5442 int32_t d2 = d->d2;
5443 int32_t ret = jwin_droplist_proc(msg,d,c);
5444
5445 if(d2!=d->d2)
5446 {
5447 joystick_index = d->d2;
5448 ret |= D_REDRAW_ALL;
5449 }
5450
5451 return ret;
5452 }
5453
5454 static DIALOG gamepad_dlg[] =
5455 {
5456 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5457 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5458 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5459 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5460 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5461 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5462 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5463 // 6
5464 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5465 // 7
5466 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5467 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5468 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5469 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5470 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5471 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5472 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5473 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5474 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5475 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5476 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5477 // 18
5478 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5479 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5480 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5481 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5482 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5483 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5484 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5485 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5486 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5487 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5488 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5489 // 29
5490 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5491 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5492 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5493 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5494 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5495 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5496 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5497 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5498 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5499 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5500 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5501 // 40
5502 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5503 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5504 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5505 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5506 // 44
5507 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5508 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5509 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5510 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5511 // 48
5512 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5513 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5514 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5515 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5516 // 52
5517 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5518 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5519 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5520 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5521 // 56
5522 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5523 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5524 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5525 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5526 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5527
5528 // 61
5529 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5530
5531 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5532 };
5533
5534 static int32_t keyboard_keys_list[] =
5535 {
5536 6,7,8,9,10,
5537 11,12,13,14,15,16,17,18,19,20,
5538 21,22,23,24,25,26,27,28,29,30,
5539 31,32,33,34,35,36,37,38,39,40,
5540 -1
5541 };
5542
5543 static int32_t keyboard_dirs_list[] =
5544 {
5545 41,42,43,44,
5546 45,46,47,48,
5547 49,50,51,52,
5548 53,54,55,56,
5549 -1
5550 };
5551
5552 static int32_t keyboard_mods_list[] =
5553 {
5554 57,58,59,60,
5555 61,62,63,64,
5556 65,66,67,68,
5557 69,70,71,72,
5558 -1
5559 };
5560
5561 static TABPANEL keyboard_control_tabs[] =
5562 {
5563 // (text)
5564 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5565 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5566 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5567 { NULL, 0, NULL, 0, NULL }
5568 };
5569
5570 static DIALOG keyboard_control_dlg[] =
5571 {
5572 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5573 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5574 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5575 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5576 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5577 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5578 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5579 // Keys
5580 // 6
5581 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5582 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5583 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5584 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5585 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5586 // 11
5587 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5588 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5589 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5590 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5591 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5592 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5593 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5594 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5595 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5596 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5597 // 21
5598 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5599 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5600 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5601 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5602 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5603 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5604 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5605 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5606 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5607 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5608 // 31
5609 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5610 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5611 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5612 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5613 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5614 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5615 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5616 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5617 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5618 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5619 // Dirs
5620 // 41
5621 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5622 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5623 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5624 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5625 // 45
5626 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5627 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5628 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5629 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5630 // 49
5631 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5632 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5633 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5634 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5635 // 53
5636 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5637 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5638 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5639 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5640 // Mods
5641 // 57
5642 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5643 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5644 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5645 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5646 // 61
5647 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5648 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5649 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5650 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5651 // 65
5652 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5653 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5654 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5655 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5656 // 69
5657 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5658 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5659 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5660 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5661 // 73
5662 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5663 };
5664
5665 int32_t midi_dp[3] = {0,0,0};
5666 int32_t emus_dp[3] = {2,0,0};
5667 int32_t sfx_dp[3] = {3,0,0};
5668 int32_t pan_dp[3] = {0,0,0};
5669
5670 static DIALOG sound_dlg[] =
5671 {
5672 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5673 411 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5674 411 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5675 411 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5676 411 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5677 411 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5678 411 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5679 411 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5680 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5681 411 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5682 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5683 // 10
5684 411 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5685 411 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5686 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5687 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5688 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5689 411 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5690 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5691 411 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5692 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5693 411 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5694 //20
5695 411 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5696 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5697 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5698 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5699 411 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5700 411 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5701 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5702 411 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5703 411 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5704 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5705 //30
5706 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5707 411 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5708 411 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5709 };
5710
5711 char zc_builddate[80];
5712 char zc_aboutstr[80];
5713
5714 static DIALOG about_dlg[] =
5715 {
5716 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5717 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5718 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5719 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5720 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5721 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5722 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5723 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5724 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5725 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5726 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5727 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5728 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5729 };
5730
5731
5732 static DIALOG quest_dlg[] =
5733 {
5734 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5735 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5736 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5737 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5738 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5739 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5740 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5741 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5742 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5743 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5744 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5745 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5746 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5747 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5748 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5749 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5750 };
5751
5752 static DIALOG triforce_dlg[] =
5753 {
5754 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5755 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5756 // 1
5757 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5758 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5759 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5760 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5761 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5762 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5763 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5764 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5765 // 9
5766 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5767 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5768 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5769 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5770 };
5771
5772 int32_t onToggleRecordingNewSaves()
5773 {
5774 if (zc_get_config("zeldadx", "replay_new_saves", false))
5775 {
5776 zc_set_config("zeldadx", "replay_new_saves", false);
5777 }
5778 else
5779 {
5780 zc_set_config("zeldadx", "replay_new_saves", true);
5781 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5782 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5783 }
5784 return D_O_K;
5785 }
5786
5787 #ifdef HAS_CURL
5788 int32_t onToggleAutoUploadReplays()
5789 {
5790 if (zc_get_config("zeldadx", "replay_upload", false))
5791 {
5792 zc_set_config("zeldadx", "replay_upload", false);
5793 }
5794 else
5795 {
5796 zc_set_config("zeldadx", "replay_upload", true);
5797 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5798 " preventing bugs and simplifying bug reports.",
5799 "Upload will happen no more than once a week when closing ZC",
5800 "OK",NULL,13,27,get_zc_font(font_lfont));
5801
5802 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5803 onToggleRecordingNewSaves();
5804 }
5805 return D_O_K;
5806 }
5807
5808 int32_t onUploadReplays()
5809 {
5810 if(jwin_alert3(
5811 "Upload replays",
5812 "Upload your replays now to assist in development?",
5813 NULL,
5814 NULL,
5815 "&Yes",
5816 "&No",
5817 NULL,
5818 'y',
5819 'n',
5820 0,
5821 get_zc_font(font_lfont)) == 1)
5822 {
5823 int num_uploaded = replay_upload();
5824 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5825 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5826 }
5827 return D_O_K;
5828 }
5829
5830 int32_t onClearUploadCache()
5831 {
5832 if(jwin_alert3(
5833 "Upload replays",
5834 "Clear the upload cache?",
5835 "This simply deletes replays/state.json. There's no harm in doing this, but",
5836 "likely is not necessary.",
5837 "&Yes",
5838 "&No",
5839 NULL,
5840 'y',
5841 'n',
5842 0,
5843 get_zc_font(font_lfont)) == 1)
5844 {
5845 replay_upload_clear_cache();
5846 }
5847 return D_O_K;
5848 }
5849 #endif
5850
5851 int32_t onToggleSnapshotAllFrames()
5852 {
5853 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5854 return D_O_K;
5855 }
5856
5857 int32_t onStopReplayOrRecord()
5858 {
5859 if (replay_is_replaying())
5860 {
5861 replay_quit();
5862 }
5863 else if (replay_get_mode() == ReplayMode::Record)
5864 {
5865 if (!replay_get_meta_bool("test_mode"))
5866 {
5867 jwin_alert("Recording", "You cannot stop recording a save file.",
5868 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5869 return D_CLOSE;
5870 }
5871
5872 if (jwin_alert("Stop Recording",
5873 "Save replay to disk and stop recording?",
5874 "This will stop the recording.",
5875 NULL,
5876 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5877 return D_CLOSE;
5878
5879 replay_save();
5880 replay_stop();
5881 }
5882 return D_O_K;
5883 }
5884
5885 static int32_t handle_on_load_replay(ReplayMode mode)
5886 {
5887 bool ctrl = CHECK_CTRL_CMD;
5888 if (Playing)
5889 {
5890 if (jwin_alert("Replay - Warning!",
5891 "Loading a replay will exit the current game.",
5892 "All unsaved progress will be lost.",
5893 "Do you wish to continue?",
5894 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5895 return D_CLOSE;
5896 }
5897
5898 std::string mode_string = replay_mode_to_string(mode);
5899 mode_string[0] = std::toupper(mode_string[0]);
5900
5901 std::string line_1 = "Select a replay file to play back.";
5902 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5903 std::string line_3 = "You can stop the replay and take over manually any time.";
5904 if (mode == ReplayMode::Update)
5905 {
5906 line_1 = "Select a replay file to update.";
5907 line_2 = "WARNING: be sure to back up the zplay file";
5908 line_3 = "and verify that the updated replay works as expected!";
5909 }
5910
5911 if (jwin_alert(mode_string.c_str(),
5912 line_1.c_str(),
5913 line_2.c_str(),
5914 line_3.c_str(),
5915 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5916 {
5917 std::string replay_path = "replays/";
5918 if(ctrl && devpwd())
5919 replay_path = "../../tests/replays/";
5920 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5921 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5922 replay_path = *result;
5923 else
5924 return D_CLOSE;
5925
5926 replay_quit();
5927 load_replay_file_deferred(mode, replay_path);
5928 Quit = qRESET;
5929 return D_CLOSE;
5930 }
5931 return D_O_K;
5932 }
5933
5934 int32_t onLoadReplay()
5935 {
5936 return handle_on_load_replay(ReplayMode::Replay);
5937 }
5938
5939 int32_t onLoadReplayAssert()
5940 {
5941 return handle_on_load_replay(ReplayMode::Assert);
5942 }
5943
5944 int32_t onLoadReplayUpdate()
5945 {
5946 return handle_on_load_replay(ReplayMode::Update);
5947 }
5948
5949 int32_t onSaveReplay()
5950 {
5951 if (replay_get_mode() == ReplayMode::Record)
5952 {
5953 if (!replay_get_meta_bool("test_mode"))
5954 {
5955 if (jwin_alert("Save Replay",
5956 "This will save a copy of the replay up to this point.",
5957 "The official replay file will be untouched.",
5958 "Do you wish to continue?",
5959 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5960 {
5961 return D_CLOSE;
5962 }
5963
5964 std::string replay_path = replay_get_replay_path().string();
5965 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5966 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5967 replay_path = *result;
5968 else
5969 return D_CLOSE;
5970
5971 if (fileexists(replay_path.c_str()))
5972 {
5973 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5974 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5975 return D_CLOSE;
5976 }
5977
5978 replay_save(replay_path);
5979 }
5980 else
5981 {
5982 replay_save();
5983 }
5984 }
5985 return D_O_K;
5986 }
5987
5988 enum
5989 {
5990 MENUID_REPLAY_RECORDNEW,
5991 MENUID_REPLAY_STOP,
5992 MENUID_REPLAY_SAVE,
5993 MENUID_REPLAY_SNAP_ALL,
5994 MENUID_REPLAY_AUTOUPLOAD,
5995 MENUID_REPLAY_UPLOAD,
5996 MENUID_REPLAY_CLEARUPLOADCACHE,
5997 };
5998
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu replay_menu
5999 5343 {
6000
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
6001
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
6002
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6003
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Load replay", onLoadReplay },
6004
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Load replay (assert)", onLoadReplayAssert },
6005
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Load replay (update)", onLoadReplayUpdate },
6006
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6007
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6008 #ifdef HAS_CURL
6009
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
6010
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6011
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6012
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6013 #endif
6014 };
6015
6016 static DIALOG credits_dlg[] =
6017 {
6018 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6019 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6020 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6021 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6022 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6023 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6024 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6025 };
6026
6027 411 static ListData dmap_list(dmaplist, &font);
6028
6029 static DIALOG goto_dlg[] =
6030 {
6031 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6032 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6033 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6034 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6035 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6036 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6037 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6038 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6039 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6040 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6041 };
6042
6043 int32_t onGoTo()
6044 {
6045 bool music = false;
6046 music = music;
6047 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6048
6049 goto_dlg[0].dp2=get_zc_font(font_lfont);
6050 goto_dlg[4].d2=cheat_goto_dmap;
6051 goto_dlg[6].dp=cheat_goto_screen_str;
6052
6053 clear_keybuf();
6054
6055 large_dialog(goto_dlg);
6056
6057 if(do_zqdialog(goto_dlg,4)==1)
6058 {
6059 int dmap = goto_dlg[4].d2;
6060 int screen = zc_xtoi(cheat_goto_screen_str);
6061 int adjusted_screen = screen + DMaps[dmap].xoff;
6062 if (adjusted_screen < 0 || adjusted_screen >= 128)
6063 {
6064 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6065 }
6066 else
6067 {
6068 cheats_enqueue(Cheat::GoTo, dmap, screen);
6069 }
6070 };
6071
6072 return D_O_K;
6073 }
6074
6075 int32_t onGoToComplete()
6076 {
6077 if(!Playing)
6078 {
6079 return D_O_K;
6080 }
6081
6082 enter_sys_pal();
6083 music_pause();
6084 pause_all_sfx();
6085 onGoTo();
6086 eat_buttons();
6087
6088 zc_readrawkey(KEY_ESC);
6089
6090 exit_sys_pal();
6091 music_resume();
6092 resume_all_sfx();
6093 return D_O_K;
6094 }
6095
6096 int32_t onCredits()
6097 {
6098 return D_O_K;
6099 }
6100
6101 const char *midilist(int32_t index, int32_t *list_size)
6102 {
6103 if(index<0)
6104 {
6105 *list_size=0;
6106
6107 for(int32_t i=0; i<MAXMIDIS; i++)
6108 if(tunes[i].data)
6109 ++(*list_size);
6110
6111 return NULL;
6112 }
6113
6114 int32_t i=0,m=0;
6115
6116 while(m<=index && i<=MAXMIDIS)
6117 {
6118 if(tunes[i].data)
6119 ++m;
6120
6121 ++i;
6122 }
6123
6124 --i;
6125
6126 if(i==MAXMIDIS && m<index)
6127 return "(null)";
6128
6129 return tunes[i].title;
6130 }
6131
6132 /* ------- MIDI info stuff -------- */
6133
6134 char *text;
6135 midi_info *zmi;
6136 bool dialog_running;
6137 bool listening;
6138
6139 void get_info(int32_t index);
6140
6141 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6142 {
6143 int32_t d2 = d->d2;
6144 int32_t ret = jwin_droplist_proc(msg,d,c);
6145
6146 if(d2!=d->d2)
6147 {
6148 get_info(d->d2);
6149 }
6150
6151 return ret;
6152 }
6153
6154 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6155 {
6156 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6157
6158 int32_t ret = jwin_button_proc(msg,d,c);
6159
6160 if(ret == D_CLOSE)
6161 {
6162 // get current midi index
6163 int32_t index = (d+(d->d1))->d2;
6164 int32_t i=0, m=0;
6165
6166 while(m<=index && i<=MAXMIDIS)
6167 {
6168 if(tunes[i].data)
6169 ++m;
6170
6171 ++i;
6172 }
6173
6174 --i;
6175 jukebox(i);
6176 listening = true;
6177 ret = D_O_K;
6178 }
6179
6180 return ret;
6181 }
6182
6183 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6184 {
6185 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6186
6187 int32_t ret = jwin_button_proc(msg,d,c);
6188
6189 if(ret == D_CLOSE)
6190 {
6191 // get current midi index
6192 int32_t index = (d+(d->d1))->d2;
6193 int32_t i=0, m=0;
6194
6195 while(m<=index && i<=MAXMIDIS)
6196 {
6197 if(tunes[i].data)
6198 ++m;
6199
6200 ++i;
6201 }
6202
6203 --i;
6204
6205 char title[40] = "Save MIDI: ";
6206 static EXT_LIST list[] =
6207 {
6208 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6209 { NULL, NULL }
6210 };
6211
6212 strcpy(title+11, tunes[i].title);
6213 title[39] = '\0';
6214
6215 std::string fname;
6216 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6217 fname = *result;
6218 else
6219 goto done;
6220
6221 if(exists(fname.c_str()))
6222 {
6223 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6224 goto done;
6225 }
6226
6227 // save midi i
6228
6229 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6230 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6231
6232 done:
6233 chop_path(fname.data());
6234 ret = D_REDRAW;
6235 }
6236
6237 return ret;
6238 }
6239
6240 411 static ListData midi_list(midilist, &font);
6241
6242 static DIALOG midi_dlg[] =
6243 {
6244 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6245 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6246 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6247 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6248 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6249 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6250 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6251 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6252 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6253 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6254 };
6255
6256 void get_info(int32_t index)
6257 {
6258 int32_t i=0, m=0;
6259
6260 while(m<=index && i<=MAXMIDIS)
6261 {
6262 if(tunes[i].data)
6263 ++m;
6264
6265 ++i;
6266 }
6267
6268 --i;
6269
6270 if(i==MAXMIDIS && m<index)
6271 strcpy(text,"(null)");
6272 else
6273 {
6274 get_midi_info(tunes[i].data,zmi);
6275 get_midi_text(tunes[i].data,zmi,text);
6276 }
6277
6278 midi_dlg[0].dp2=get_zc_font(font_lfont);
6279 midi_dlg[3].dp = text;
6280 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6281 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6282
6283 if(dialog_running)
6284 {
6285 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6286 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6287 }
6288 }
6289
6290 int32_t onMIDICredits()
6291 {
6292 text = (char*)malloc(4096);
6293 zmi = (midi_info*)malloc(sizeof(midi_info));
6294
6295 if(!text || !zmi)
6296 {
6297 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6298 return D_O_K;
6299 }
6300
6301 bool do_pause_midi = midi_pos >= 0 && currmidi;
6302 auto restore_midi = currmidi;
6303 if(do_pause_midi)
6304 {
6305 paused_midi_pos = midi_pos;
6306 stop_midi();
6307 midi_suspended = midissuspHALTED;
6308 }
6309
6310 midi_dlg[0].dp2=get_zc_font(font_lfont);
6311 midi_dlg[2].d1 = 0;
6312 midi_dlg[2].d2 = 0;
6313 midi_dlg[4].flags = D_EXIT;
6314 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6315
6316 listening = false;
6317 dialog_running=false;
6318 get_info(0);
6319
6320 dialog_running=true;
6321
6322 large_dialog(midi_dlg);
6323
6324 do_zqdialog(midi_dlg,0);
6325 dialog_running=false;
6326
6327 if(listening)
6328 music_stop();
6329
6330 if(do_pause_midi)
6331 {
6332 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6333 midi_suspended = midissuspRESUME;
6334 currmidi = restore_midi;
6335 midi_pos = paused_midi_pos;
6336 }
6337
6338 if(text) free(text);
6339 if(zmi) free(zmi);
6340 return D_O_K;
6341 }
6342
6343 int32_t onAbout()
6344 {
6345 char buf1[80]={0};
6346 std::ostringstream oss;
6347 sprintf(buf1,"ZQuest Classic Player");
6348 oss << buf1 << '\n';
6349 sprintf(buf1,"Version: %s", getVersionString());
6350 oss << buf1 << '\n';
6351 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6352 oss << buf1 << '\n';
6353
6354 InfoDialog("About ZC", oss.str()).show();
6355 return D_O_K;
6356 }
6357
6358 int32_t onQuest()
6359 {
6360 char fname[100];
6361 strcpy(fname, get_filename(qstpath));
6362 quest_dlg[0].dp2=get_zc_font(font_lfont);
6363 quest_dlg[1].dp = fname;
6364
6365 if(QHeader.quest_number==0)
6366 sprintf(str_a,"Custom");
6367 else
6368 sprintf(str_a,"%d",QHeader.quest_number);
6369
6370 sprintf(str_s,"%s",QHeader.getVerStr());
6371
6372 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6373 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6374
6375 large_dialog(quest_dlg);
6376
6377 do_zqdialog(quest_dlg, 0);
6378 return D_O_K;
6379 }
6380
6381 void call_vidmode_dlg();
6382 int32_t onVidMode()
6383 {
6384 call_vidmode_dlg();
6385 return D_O_K;
6386 }
6387
6388 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6389 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6390 //Added an extra statement, so that if the key is cleared to 0, the cleared
6391 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6392
6393 void load_ukeys(int32_t* arr)
6394 {
6395 arr[ukey_a] = Akey;
6396 arr[ukey_b] = Bkey;
6397 arr[ukey_s] = Skey;
6398 arr[ukey_l] = Lkey;
6399 arr[ukey_r] = Rkey;
6400 arr[ukey_p] = Pkey;
6401 arr[ukey_ex1] = Exkey1;
6402 arr[ukey_ex2] = Exkey2;
6403 arr[ukey_ex3] = Exkey3;
6404 arr[ukey_ex4] = Exkey4;
6405 arr[ukey_du] = DUkey;
6406 arr[ukey_dd] = DDkey;
6407 arr[ukey_dl] = DLkey;
6408 arr[ukey_dr] = DRkey;
6409 arr[ukey_mod1a] = cheat_modifier_keys[0];
6410 arr[ukey_mod1b] = cheat_modifier_keys[1];
6411 arr[ukey_mod2a] = cheat_modifier_keys[2];
6412 arr[ukey_mod2b] = cheat_modifier_keys[3];
6413 };
6414
6415 static const char* ukey_names[] = {
6416 "A", "B", "Start", "L", "R", "Map",
6417 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6418 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6419 "Cheat Mod R1", "Cheat Mod R2",
6420 };
6421 std::string get_ukey_name(int32_t k)
6422 {
6423 if (k < num_ukey) return ukey_names[k];
6424 return "";
6425 }
6426
6427 int32_t onKeyboard()
6428 {
6429 int32_t a = Akey;
6430 int32_t b = Bkey;
6431 int32_t s = Skey;
6432 int32_t l = Lkey;
6433 int32_t r = Rkey;
6434 int32_t p = Pkey;
6435 int32_t ex1 = Exkey1;
6436 int32_t ex2 = Exkey2;
6437 int32_t ex3 = Exkey3;
6438 int32_t ex4 = Exkey4;
6439 int32_t du = DUkey;
6440 int32_t dd = DDkey;
6441 int32_t dl = DLkey;
6442 int32_t dr = DRkey;
6443 int32_t mod1a = cheat_modifier_keys[0];
6444 int32_t mod1b = cheat_modifier_keys[1];
6445 int32_t mod2a = cheat_modifier_keys[2];
6446 int32_t mod2b = cheat_modifier_keys[3];
6447 bool done=false;
6448 int32_t ret;
6449
6450 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6451
6452 large_dialog(keyboard_control_dlg);
6453
6454 while(!done)
6455 {
6456 ret = do_zqdialog(keyboard_control_dlg,3);
6457
6458 if(ret==3) // OK
6459 {
6460 int32_t ukeys[num_ukey];
6461 load_ukeys(ukeys);
6462 std::vector<std::string> uniqueError;
6463 for(int32_t q = 0; q < num_ukey; ++q)
6464 {
6465 for(int32_t p = q+1; p < num_ukey; ++p)
6466 {
6467 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6468 {
6469 char buf[64];
6470 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6471 std::string str(buf);
6472 uniqueError.push_back(str);
6473 }
6474 }
6475 }
6476 if(uniqueError.size() == 0)
6477 {
6478 done = true;
6479 save_control_configs(true);
6480 }
6481 else
6482 {
6483 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6484 box_out("Cannot have duplicate keybinds!"); box_eol();
6485 for(std::vector<std::string>::iterator it = uniqueError.begin();
6486 it != uniqueError.end(); ++it)
6487 {
6488 box_out((*it).c_str()); box_eol();
6489 }
6490 box_end(true);
6491 }
6492 }
6493 else // Cancel
6494 {
6495 Akey = a;
6496 Bkey = b;
6497 Skey = s;
6498 Lkey = l;
6499 Rkey = r;
6500 Pkey = p;
6501 Exkey1 = ex1;
6502 Exkey2 = ex2;
6503 Exkey3 = ex3;
6504 Exkey4 = ex4;
6505 DUkey = du;
6506 DDkey = dd;
6507 DLkey = dl;
6508 DRkey = dr;
6509 cheat_modifier_keys[0] = mod1a;
6510 cheat_modifier_keys[1] = mod1b;
6511 cheat_modifier_keys[2] = mod2a;
6512 cheat_modifier_keys[3] = mod2b;
6513
6514 done=true;
6515 }
6516
6517 rest(1);
6518 }
6519
6520 return D_O_K;
6521 }
6522
6523 int32_t onGamepad()
6524 {
6525 if (al_get_num_joysticks() == 0)
6526 {
6527 InfoDialog("ZC", "No gamepads detected.").show();
6528 return D_O_K;
6529 }
6530
6531 int32_t a = Abtn;
6532 int32_t b = Bbtn;
6533 int32_t s = Sbtn;
6534 int32_t l = Lbtn;
6535 int32_t r = Rbtn;
6536 int32_t m = Mbtn;
6537 int32_t p = Pbtn;
6538 int32_t ex1 = Exbtn1;
6539 int32_t ex2 = Exbtn2;
6540 int32_t ex3 = Exbtn3;
6541 int32_t ex4 = Exbtn4;
6542 int32_t up = DUbtn;
6543 int32_t down = DDbtn;
6544 int32_t left = DLbtn;
6545 int32_t right = DRbtn;
6546 int32_t joy = joystick_index;
6547 int32_t stick_1 = js_stick_1_x_stick;
6548 int32_t stick_2 = js_stick_2_x_stick;
6549
6550 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6551 if(analog_movement)
6552 gamepad_dlg[56].flags|=D_SELECTED;
6553 else
6554 gamepad_dlg[56].flags&=~D_SELECTED;
6555
6556 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6557 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6558 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6559 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6560 // requires remapping every time.
6561 if (joystick_index >= al_get_num_joysticks())
6562 joystick_index = 0;
6563 gamepad_dlg[61].d2 = joystick_index;
6564
6565 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6566 if (!gamepad_dlg_cur_joystick)
6567 {
6568 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6569 return D_CLOSE;
6570 }
6571
6572 large_dialog(gamepad_dlg);
6573
6574 int32_t ret = do_zqdialog(gamepad_dlg,4);
6575
6576 if(ret == 4) //OK
6577 {
6578 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6579 joystick_index = gamepad_dlg[61].d2;
6580 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6581 if (!gamepad_dlg_cur_joystick)
6582 {
6583 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6584 return D_CLOSE;
6585 }
6586 js_stick_1_y_stick = js_stick_1_x_stick;
6587 js_stick_2_y_stick = js_stick_2_x_stick;
6588 save_control_configs(false);
6589 }
6590 else //Cancel
6591 {
6592 Abtn = a;
6593 Bbtn = b;
6594 Sbtn = s;
6595 Lbtn = l;
6596 Rbtn = r;
6597 Mbtn = m;
6598 Pbtn = p;
6599 Exbtn1 = ex1;
6600 Exbtn2 = ex2;
6601 Exbtn3 = ex3;
6602 Exbtn4 = ex4;
6603 DUbtn = up;
6604 DDbtn = down;
6605 DLbtn = left;
6606 DRbtn = right;
6607 joystick_index = joy;
6608 js_stick_1_x_stick = stick_1;
6609 js_stick_2_x_stick = stick_2;
6610 }
6611
6612 return D_O_K;
6613 }
6614
6615 int32_t onCheatKeys()
6616 {
6617 int32_t oldcheats[Cheat::Last][2];
6618 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6619
6620 bool done=false;
6621
6622 while(!done)
6623 {
6624 bool confirm = false;
6625 CheatKeysDialog(&confirm).show();
6626 if(confirm) // OK
6627 {
6628 std::vector<std::string> uniqueError;
6629 char buf[512];
6630 for(size_t q = 1; q < Cheat::Last; ++q)
6631 {
6632 if(cheatkeys[q][1] && !cheatkeys[q][0])
6633 {
6634 cheatkeys[q][0] = cheatkeys[q][1];
6635 cheatkeys[q][1] = 0;
6636 }
6637 }
6638 for(size_t q = 1; q < Cheat::Last; ++q)
6639 {
6640 if(!bindable_cheat((Cheat)q)) continue;
6641 for(size_t p = q+1; p < Cheat::Last; ++p)
6642 {
6643 if(!bindable_cheat((Cheat)p)) continue;
6644 for(size_t q2 = 0; q2 <= 1; ++q2)
6645 for(size_t p2 = 0; p2 <= 1; ++p2)
6646 {
6647 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6648 {
6649 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6650 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6651 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6652 get_keystr(cheatkeys[q][q2])));
6653 }
6654 }
6655 }
6656 }
6657 if(uniqueError.size() == 0)
6658 {
6659 done = true;
6660 save_cheatkeys();
6661 }
6662 else
6663 {
6664 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6665 box_out("Cannot have duplicate keybinds!"); box_eol();
6666 for(std::vector<std::string>::iterator it = uniqueError.begin();
6667 it != uniqueError.end(); ++it)
6668 {
6669 box_out((*it).c_str()); box_eol();
6670 }
6671 box_end(true);
6672 }
6673 }
6674 else // Cancel
6675 {
6676 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6677 done=true;
6678 }
6679 rest(1);
6680 }
6681
6682 return D_O_K;
6683 }
6684
6685 int32_t onSound()
6686 {
6687 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6688 {
6689 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6690 {
6691 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6692 }
6693 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6694 {
6695 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6696 }
6697 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6698 {
6699 emusic_volume = (int32_t)FFCore.usr_music_volume;
6700 }
6701 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6702 {
6703 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6704 }
6705 }
6706 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6707 {
6708 pan_style = (int32_t)FFCore.usr_panstyle;
6709 }
6710
6711 int32_t m = midi_volume;
6712 int32_t e = emusic_volume;
6713 int32_t s = sfx_volume;
6714 int32_t p = pan_style;
6715 pan_style = vbound(pan_style,0,3);
6716
6717 sound_dlg[0].dp2=get_zc_font(font_lfont);
6718
6719 large_dialog(sound_dlg);
6720
6721 midi_dp[1] = sound_dlg[6].x;
6722 midi_dp[2] = sound_dlg[6].y;
6723 emus_dp[1] = sound_dlg[8].x;
6724 emus_dp[2] = sound_dlg[8].y;
6725 sfx_dp[1] = sound_dlg[10].x;
6726 sfx_dp[2] = sound_dlg[10].y;
6727 pan_dp[1] = sound_dlg[11].x;
6728 pan_dp[2] = sound_dlg[11].y;
6729 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6730 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6731 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6732 sound_dlg[20].d2 = pan_style;
6733
6734 int32_t ret = do_zqdialog(sound_dlg,1);
6735
6736 if(ret==2)
6737 {
6738 master_volume(digi_volume,midi_volume);
6739 if (zcmusic)
6740 zcmusic_set_volume(zcmusic, emusic_volume);
6741
6742 int32_t temp_volume = sfx_volume;
6743 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6744 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6745 for(int32_t i=0; i<WAV_COUNT; ++i)
6746 {
6747 if(sfx_voice[i] >= 0)
6748 voice_set_volume(sfx_voice[i], temp_volume);
6749 }
6750 zc_set_config(sfx_sect,"midi",midi_volume);
6751 zc_set_config(sfx_sect,"sfx",sfx_volume);
6752 zc_set_config(sfx_sect,"emusic",emusic_volume);
6753 zc_set_config(sfx_sect,"pan",pan_style);
6754 }
6755 else
6756 {
6757 midi_volume = m;
6758 emusic_volume = e;
6759 sfx_volume = s;
6760 pan_style = p;
6761 }
6762
6763 return D_O_K;
6764 }
6765
6766 int32_t queding(char const* s1, char const* s2, char const* s3)
6767 {
6768 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6769 }
6770
6771 int32_t onQuit()
6772 {
6773 if(Playing)
6774 {
6775 int32_t ret=0;
6776
6777 if(get_qr(qr_NOCONTINUE))
6778 {
6779 if(standalone_mode)
6780 {
6781 ret=queding("End current game?",
6782 "The continue screen is disabled; the game",
6783 "will be reloaded from the last save.");
6784 }
6785 else
6786 {
6787 ret=queding("End current game?",
6788 "The continue screen is disabled. You will",
6789 "be returned to the file select screen.");
6790 }
6791 }
6792 else
6793 ret=queding("End current game?",NULL,NULL);
6794
6795 if(ret==1)
6796 {
6797 disableClickToFreeze=false;
6798 Quit=qQUIT;
6799
6800 // Trying to evade a door repair charge?
6801 if(repaircharge)
6802 {
6803 game->change_drupy(-repaircharge);
6804 repaircharge=0;
6805 }
6806
6807 return D_CLOSE;
6808 }
6809 }
6810
6811 return D_O_K;
6812 }
6813
6814 int32_t onTryQuitMenu()
6815 {
6816 return onTryQuit(true);
6817 }
6818
6819 int32_t onTryQuit(bool inMenu)
6820 {
6821 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6822 {
6823 if(active_cutscene.can_f6())
6824 {
6825 if(get_qr(qr_OLD_F6))
6826 {
6827 if(inMenu) onQuit();
6828 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6829 }
6830 else
6831 {
6832 disableClickToFreeze=false;
6833 GameFlags |= GAMEFLAG_TRYQUIT;
6834 }
6835 return D_CLOSE;
6836 }
6837 else active_cutscene.error();
6838 }
6839
6840 return D_O_K;
6841 }
6842
6843 int32_t onReset()
6844 {
6845 if(queding(" Reset system? ",NULL,NULL)==1)
6846 {
6847 disableClickToFreeze=false;
6848 Quit=qRESET;
6849 replay_quit();
6850 return D_CLOSE;
6851 }
6852
6853 return D_O_K;
6854 }
6855
6856 int32_t onExit()
6857 {
6858 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6859 {
6860 Quit=qEXIT;
6861 return D_CLOSE;
6862 }
6863
6864 return D_O_K;
6865 }
6866
6867 int32_t onDebug()
6868 {
6869 if(debug_enabled)
6870 set_debug(!get_debug());
6871 return D_O_K;
6872 }
6873
6874 int32_t onHeartBeep()
6875 {
6876 heart_beep=!heart_beep;
6877 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6878 return D_O_K;
6879 }
6880
6881 int32_t onSaveIndicator()
6882 {
6883 use_save_indicator = use_save_indicator ? 0 : 1;
6884 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6885 return D_O_K;
6886 }
6887
6888 int32_t onEpilepsy()
6889 {
6890 if(jwin_alert3(
6891 "Epilepsy Flash Reduction",
6892 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6893 "Disabling this will restore standard flash and wavy behaviour.",
6894 "Proceed?",
6895 "&Yes",
6896 "&No",
6897 NULL,
6898 'y',
6899 'n',
6900 0,
6901 get_zc_font(font_lfont)) == 1)
6902 {
6903 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6904 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6905 }
6906 return D_O_K;
6907 }
6908
6909 bool rc = false;
6910
6911 static DIALOG getnum_dlg[] =
6912 {
6913 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6914 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6915 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6916 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6917 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6918 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6919 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6920 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6921 };
6922
6923 int32_t getnumber(const char *prompt,int32_t initialval)
6924 {
6925 char buf[20];
6926 sprintf(buf,"%d",initialval);
6927 getnum_dlg[0].dp=(void *)prompt;
6928 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6929 getnum_dlg[2].dp=buf;
6930
6931 large_dialog(getnum_dlg);
6932
6933 if(do_zqdialog(getnum_dlg,2)==3)
6934 return atoi(buf);
6935
6936 return initialval;
6937 }
6938
6939 int32_t onLife()
6940 {
6941 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6942 cheats_enqueue(Cheat::Life, value);
6943 return D_O_K;
6944 }
6945
6946 int32_t onHeartC()
6947 {
6948 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6949 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6950 cheats_enqueue(Cheat::MaxLife, max_life);
6951 cheats_enqueue(Cheat::Life, life);
6952 return D_O_K;
6953 }
6954
6955 int32_t onMagicC()
6956 {
6957 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6958 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6959 cheats_enqueue(Cheat::MaxMagic, max_magic);
6960 cheats_enqueue(Cheat::Magic, magic);
6961 return D_O_K;
6962 }
6963
6964 int32_t onRupies()
6965 {
6966 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6967 cheats_enqueue(Cheat::Rupies, value);
6968 return D_O_K;
6969 }
6970
6971 int32_t onMaxBombs()
6972 {
6973 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6974 cheats_enqueue(Cheat::MaxBombs, value);
6975 cheats_enqueue(Cheat::Bombs, value);
6976 return D_O_K;
6977 }
6978
6979 int32_t onRefillLife()
6980 {
6981 cheats_enqueue(Cheat::Life, game->get_maxlife());
6982 return D_O_K;
6983 }
6984 int32_t onRefillMagic()
6985 {
6986 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6987 return D_O_K;
6988 }
6989 int32_t onClock()
6990 {
6991 cheats_enqueue(Cheat::Clock);
6992 return D_O_K;
6993 }
6994
6995 int32_t onQstPath()
6996 {
6997 char initial_path[2048];
6998 chop_path(qstdir);
6999 strcpy(initial_path, qstdir);
7000
7001 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
7002 {
7003 char* path = result->data();
7004 chop_path(path);
7005 fix_filename_case(path);
7006 fix_filename_slashes(path);
7007 strcpy(qstdir,path);
7008 strcpy(qstpath,qstdir);
7009 zc_set_config("zeldadx","quest_dir",qstdir);
7010 flush_config_file();
7011 }
7012
7013 return D_O_K;
7014 }
7015
7016 #include "dialog/cheat_dialog.h"
7017 int32_t onCheat()
7018 {
7019 call_setcheat_dialog();
7020 game->set_cheat(maxcheat);
7021 if(cheat) game->did_cheat(true);
7022 return D_O_K;
7023 }
7024
7025 int32_t onCheatRupies()
7026 {
7027 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7028 return D_O_K;
7029 }
7030
7031 int32_t onCheatArrows()
7032 {
7033 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7034 return D_O_K;
7035 }
7036
7037 int32_t onCheatBombs()
7038 {
7039 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7040 return D_O_K;
7041 }
7042
7043 // *** screen saver
7044
7045 18521867 int32_t after_time()
7046 {
7047
1/2
✓ Branch 0 taken 18521867 times.
✗ Branch 1 not taken.
18521867 if(ss_enable == 0)
7048 return INT_MAX;
7049
7050
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18521867 times.
18521867 if(ss_after <= 0)
7051 return 5 * 60;
7052
7053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18521867 times.
18521867 if(ss_after <= 3)
7054 return ss_after * 15 * 60;
7055
7056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18521867 times.
18521867 if(ss_after <= 13)
7057 return (ss_after - 3) * 60 * 60;
7058
7059 18521867 return MAX_IDLE + 1;
7060 18521867 }
7061
7062 static const char *after_str[15] =
7063 {
7064 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7065 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7066 "Never"
7067 };
7068
7069 const char *after_list(int32_t index, int32_t *list_size)
7070 {
7071 if(index < 0)
7072 {
7073 *list_size = 15;
7074 return NULL;
7075 }
7076
7077 return after_str[index];
7078 }
7079
7080 411 static ListData after__list(after_list, &font);
7081
7082 static DIALOG scrsaver_dlg[] =
7083 {
7084 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7085 411 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7086 411 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7087 411 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7088 411 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7089 411 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7090 411 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7091 411 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7092 411 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7093 411 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7094 411 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7095 411 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7096 411 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7097 411 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7098 };
7099
7100 int32_t onScreenSaver()
7101 {
7102 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7103 int32_t oldcfgs[3];
7104 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7105 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7106 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7107
7108 large_dialog(scrsaver_dlg);
7109
7110 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7111
7112 if(ret == 8 || ret == 9)
7113 {
7114 ss_after = scrsaver_dlg[5].d1;
7115 ss_speed = scrsaver_dlg[6].d2;
7116 ss_density = scrsaver_dlg[7].d2;
7117 if(oldcfgs[0] != ss_after)
7118 zc_set_config(cfg_sect,"ss_after",ss_after);
7119 if(oldcfgs[1] != ss_speed)
7120 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7121 if(oldcfgs[2] != ss_density)
7122 zc_set_config(cfg_sect,"ss_density",ss_density);
7123 }
7124
7125 if(ret == 9)
7126 // preview Screen Saver
7127 {
7128 clear_keybuf();
7129 Matrix(ss_speed, ss_density, 30);
7130 system_pal(true);
7131 sys_mouse();
7132 }
7133
7134 return D_O_K;
7135 }
7136
7137 /***** Menus *****/
7138
7139 enum
7140 {
7141 MENUID_GAME_LOADQUEST,
7142 MENUID_GAME_ENDGAME,
7143 };
7144
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu game_menu
7145 3288 {
7146
3/6
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
411 { "&Continue","ESC", onContinue },
7147
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
7148
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7149
3/6
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
411 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7150
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
7151 #ifdef __EMSCRIPTEN__
7152 { "&Reset","F7", onReset },
7153 #elif defined(ALLEGRO_MACOSX)
7154 { "&Reset","F7", onReset },
7155 { "&Quit","F8", onExit },
7156 #else
7157
3/6
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
411 { "&Reset","F9", onReset },
7158
3/6
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
411 { "&Quit","F10", onExit },
7159 #endif
7160 };
7161
7162
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu snapshot_format_menu
7163 2877 {
7164
4/8
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 411 times.
✗ Branch 7 not taken.
411 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7165
4/8
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 411 times.
✗ Branch 7 not taken.
411 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7166
4/8
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 411 times.
✗ Branch 7 not taken.
411 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7167
4/8
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 411 times.
✗ Branch 7 not taken.
411 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7168
4/8
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 411 times.
✗ Branch 7 not taken.
411 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7169
4/8
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 411 times.
✗ Branch 7 not taken.
411 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7170 };
7171
7172
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu bottom_8_pixels_menu
7173 1644 {
7174
4/8
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 411 times.
✗ Branch 7 not taken.
411 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7175
4/8
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 411 times.
✗ Branch 7 not taken.
411 { "&On", std::bind(onSetBottom8Pixels, 1) },
7176
4/8
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 411 times.
✗ Branch 7 not taken.
411 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7177 };
7178
7179
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu controls_menu
7180 1644 {
7181
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Key&board...", onKeyboard },
7182
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Gamepad...", onGamepad },
7183
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Cheat Keys...", onCheatKeys },
7184 };
7185
7186
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu name_entry_mode_menu
7187 1644 {
7188
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Keyboard", onKeyboardEntry },
7189
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Letter Grid", onLetterGridEntry },
7190
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Extended Letter Grid", onExtLetterGridEntry },
7191 };
7192
7193 static void set_controls_menu_active()
7194 {
7195
7196 }
7197
7198 enum
7199 {
7200 MENUID_WINDOW_LOCK_ASPECT,
7201 MENUID_WINDOW_LOCK_INTSCALE,
7202 MENUID_WINDOW_SAVE_SIZE,
7203 MENUID_WINDOW_SAVE_POS,
7204 MENUID_WINDOW_STRETCH,
7205 };
7206
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu window_menu
7207 2466 {
7208
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7209
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7210
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7211
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7212
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7213 };
7214 void call_zc_options_dlg();
7215 enum
7216 {
7217 MENUID_OPTIONS_PAUSE_BG,
7218 MENUID_OPTIONS_EPILEPSYPROT,
7219 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7220 };
7221
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu options_menu
7222 3288 {
7223
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Name &Entry Mode", &name_entry_mode_menu },
7224
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "S&napshot Format", &snapshot_format_menu },
7225
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Window Settings", &window_menu },
7226
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7227
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7228
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7229
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "More Options", call_zc_options_dlg },
7230 };
7231 enum
7232 {
7233 MENUID_SETTINGS_CONTROLS,
7234 MENUID_SETTINGS_CAPFPS,
7235 MENUID_SETTINGS_SHOWFPS,
7236 MENUID_SETTINGS_SHOWTIME,
7237 MENUID_SETTINGS_CLICK_FREEZE,
7238 MENUID_SETTINGS_TRANSLAYERS,
7239 MENUID_SETTINGS_NESQUIT,
7240 MENUID_SETTINGS_VOLKEYS,
7241 MENUID_SETTINGS_HEARTBEEP,
7242 MENUID_SETTINGS_SAVEINDICATOR,
7243 MENUID_SETTINGS_DEBUG,
7244 };
7245
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu settings_menu
7246 6987 {
7247
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Sound...", onSound },
7248
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7249
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
7250
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Options", &options_menu },
7251
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
7252
3/6
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
411 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7253
3/6
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
411 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7254
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7255
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7256
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7257
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7258
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7259
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7260
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7261
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
7262
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7263 };
7264
7265 enum
7266 {
7267 MENUID_MISC_FULLSCREEN,
7268 MENUID_MISC_VIDMODE,
7269 MENUID_MISC_QUEST_INFO,
7270 MENUID_MISC_QUEST_DIR,
7271 MENUID_MISC_CONSOLE,
7272 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7273 };
7274
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu misc_menu
7275 6165 {
7276
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&About...", onAbout },
7277 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7278 // { "&Credits...", onCredits },
7279
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7280
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7281
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
7282
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7283
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Quest &MIDI Info...", onMIDICredits },
7284
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7285
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
7286
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Take &Snapshot F12", onSnapshot },
7287
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Sc&reen Saver...", onScreenSaver },
7288
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Save ZC Configuration", OnSaveZCConfig },
7289
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7290
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7291
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Clear Directory Cache", OnnClearQuestDir },
7292 };
7293
7294 enum
7295 {
7296 MENUID_REFILL_ARROWS,
7297 };
7298
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu refill_menu
7299 2466 {
7300
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Life", onRefillLife },
7301
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Magic", onRefillMagic },
7302
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Bombs", onCheatBombs },
7303
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Rupees", onCheatRupies },
7304
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7305 };
7306
7307 enum
7308 {
7309 MENUID_SHOW_L0,
7310 MENUID_SHOW_L1,
7311 MENUID_SHOW_L2,
7312 MENUID_SHOW_L3,
7313 MENUID_SHOW_L4,
7314 MENUID_SHOW_L5,
7315 MENUID_SHOW_L6,
7316 MENUID_SHOW_OVER,
7317 MENUID_SHOW_PUSH,
7318 MENUID_SHOW_FFC,
7319 MENUID_SHOW_SPR,
7320 MENUID_SHOW_SCRIPTNAME,
7321 MENUID_SHOW_SOLIDITY,
7322 MENUID_SHOW_HITBOX,
7323 MENUID_SHOW_EFFECT,
7324 };
7325
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu show_menu
7326 7809 {
7327
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7328
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7329
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7330
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7331
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7332
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7333
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7334
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7335
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7336
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7337
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7338
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
7339
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7340
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 {},
7341
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7342
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7343
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7344
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Info Opacity", onShowInfoOpacity },
7345 };
7346
7347 enum
7348 {
7349 MENUID_CHEAT_CHOP_L1,
7350 MENUID_CHEAT_CHOP_L2,
7351 MENUID_CHEAT_CHOP_L3,
7352 MENUID_CHEAT_CHOP_L4,
7353 MENUID_CHEAT_INVULN,
7354 MENUID_CHEAT_NOCLIP,
7355 MENUID_CHEAT_IGNORESV,
7356 MENUID_CHEAT_GOFAST,
7357 };
7358
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 static NewMenu cheat_menu
7359 6987 {
7360
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Set &Cheat", onCheat },
7361
1/2
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
411 { MENUID_CHEAT_CHOP_L1 },
7362
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Re&fill", &refill_menu },
7363
1/2
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
411 { MENUID_CHEAT_CHOP_L2 },
7364
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7365
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Ma&x Bombs...", onMaxBombs },
7366
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Heart Containers...", onHeartC },
7367
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Magic Containers...", onMagicC },
7368
1/2
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
411 { MENUID_CHEAT_CHOP_L3 },
7369
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Hero Data...", onCheatConsole },
7370
1/2
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
411 { MENUID_CHEAT_CHOP_L4 },
7371
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7372
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7373
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7374
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Kill All Enemies", onKillCheat },
7375
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Trigger &Secrets", onSecretsCheat },
7376
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Trigger Secrets Perm", onSecretsCheatPerm },
7377
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Show/Hide Layer", &show_menu },
7378
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "Toggle &Light", onLightSwitch },
7379
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Goto Location...", onGoTo },
7380 };
7381
7382 #if DEVLEVEL > 0
7383 int32_t devLogging();
7384 int32_t devDebug();
7385 int32_t devTimestmp();
7386 #if DEVLEVEL > 1
7387 int32_t setCheat();
7388 #endif //DEVLEVEL > 1
7389 enum
7390 {
7391 MENUID_DEV_LOGGING,
7392 MENUID_DEV_DEBUG,
7393 MENUID_DEV_TIMESTAMP,
7394 MENUID_DEV_SETCHEAT,
7395 };
7396 static NewMenu dev_menu
7397 {
7398 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7399 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7400 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7401 #if DEVLEVEL > 1
7402 {},
7403 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7404 #endif //DEVLEVEL > 1
7405 };
7406 int32_t devLogging()
7407 {
7408 dev_logging = !dev_logging;
7409 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7410 return D_O_K;
7411 }
7412 // int32_t devDebug()
7413 // {
7414 // dev_debug = !dev_debug;
7415 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7416 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7417 // return D_O_K;
7418 // }
7419 int32_t devTimestmp()
7420 {
7421 dev_timestmp = !dev_timestmp;
7422 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7423 return D_O_K;
7424 }
7425 #if DEVLEVEL > 1
7426 int32_t setCheat()
7427 {
7428 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7429 return D_O_K;
7430 }
7431 #endif //DEVLEVEL > 1
7432 #endif //DEVLEVEL > 0
7433
7434 enum
7435 {
7436 MENUID_PLAYER_CHEAT,
7437 };
7438
1/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
411 TopMenu the_player_menu
7439 2466 {
7440
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Game", &game_menu },
7441
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Settings", &settings_menu },
7442
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7443
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&Replay", &replay_menu },
7444
2/4
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 411 times.
✗ Branch 3 not taken.
411 { "&ZC", &misc_menu },
7445 #if DEVLEVEL > 0
7446 { "&Dev", &dev_menu },
7447 #endif
7448 };
7449
7450 int32_t onPauseInBackground()
7451 {
7452 if(jwin_alert3(
7453 "Toggle Pause In Background",
7454 "This action will change whether ZC Player pauses when the window loses focus.",
7455 "",
7456 "Proceed?",
7457 "&Yes",
7458 "&No",
7459 NULL,
7460 'y',
7461 'n',
7462 0,
7463 get_zc_font(font_lfont)) == 1)
7464 {
7465 pause_in_background = pause_in_background ? 0 : 1;
7466 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7467 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7468 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7469 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7470 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7471 }
7472 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7473 return D_O_K;
7474 }
7475
7476 int32_t onKeyboardEntry()
7477 {
7478 NameEntryMode=0;
7479 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7480 return D_O_K;
7481 }
7482
7483 int32_t onLetterGridEntry()
7484 {
7485 NameEntryMode=1;
7486 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7487 return D_O_K;
7488 }
7489
7490 int32_t onExtLetterGridEntry()
7491 {
7492 NameEntryMode=2;
7493 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7494 return D_O_K;
7495 }
7496
7497 static BITMAP* oldscreen;
7498 int32_t onFullscreenMenu()
7499 {
7500 PALETTE oldpal;
7501 get_palette(oldpal);
7502
7503 fullscreen = !fullscreen;
7504 all_toggle_fullscreen(fullscreen);
7505 zc_set_config("zeldadx","fullscreen",fullscreen);
7506
7507 zc_set_palette(oldpal);
7508 gui_mouse_focus=0;
7509 extern int32_t switch_type;
7510 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7511 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7512 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7513 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7514 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7515 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7516
7517 return D_O_K;
7518 }
7519
7520 314 void fix_menu()
7521 {
7522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
314 if(!debug_enabled)
7523 314 settings_menu.chop_index = 13;
7524 314 }
7525
7526 int32_t onSetSnapshotFormat(SnapshotType format)
7527 {
7528 SnapshotFormat = format;
7529 zc_set_config("zeldadx", "snapshot_format", format);
7530 snapshot_format_menu.select_only_index(format);
7531 return D_O_K;
7532 }
7533
7534 int32_t onSetBottom8Pixels(int option)
7535 {
7536 ShowBottomPixels = option;
7537 zc_set_config("zeldadx", "bottom_8_px", option);
7538 bottom_8_pixels_menu.select_only_index(option);
7539
7540 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7541 bool value = false;
7542 if (option == 0)
7543 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7544 else if (option == 1)
7545 value = false;
7546 else if (option == 2)
7547 value = true;
7548 enqueue_qr_change(qr, value);
7549
7550 return D_O_K;
7551 }
7552
7553 2917 void updateShowBottomPixels()
7554 {
7555 // It's too tricky the allow modifying the screen height between opening and closing the
7556 // active subscreen.
7557
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2891 times.
2917 if (subscreen_open)
7558 26 return;
7559
7560
1/2
✓ Branch 0 taken 2891 times.
✗ Branch 1 not taken.
2891 if (!GameLoaded)
7561 show_bottom_8px = false;
7562 else
7563 2891 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7564
7565 2891 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7566
2/2
✓ Branch 0 taken 2791 times.
✓ Branch 1 taken 100 times.
2891 if (framebuf->h != target_bitmap_height)
7567 {
7568 100 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7569 100 clear_bitmap(new_framebuf);
7570 100 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7571
7572 100 destroy_bitmap(framebuf);
7573 100 destroy_bitmap(script_menu_buf);
7574 100 destroy_bitmap(f6_menu_buf);
7575 100 destroy_bitmap(darkscr_bmp);
7576 100 destroy_bitmap(darkscr_bmp_trans);
7577
7578 100 framebuf = new_framebuf;
7579 100 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7580 100 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7581 100 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7582 100 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7583
7584 100 rti_game.a4_bitmap = framebuf;
7585 100 rti_game.set_size(framebuf->w, framebuf->h);
7586 100 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7587 100 al_destroy_bitmap(rti_game.bitmap);
7588 100 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7589 100 al_destroy_bitmap(rti_infolayer.bitmap);
7590 100 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7591 100 rti_infolayer.set_size(framebuf->w, framebuf->h);
7592 100 }
7593 2917 }
7594
7595 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7596 {
7597 PALETTE tmp;
7598
7599 for(int32_t i=0; i<256; i++)
7600 {
7601 tmp[i].r=r;
7602 tmp[i].g=g;
7603 tmp[i].b=b;
7604 }
7605
7606 fade_interpolate(src,tmp,dest,pos,from,to);
7607 }
7608
7609 46 void system_pal(bool force)
7610 {
7611
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46 if(is_sys_pal && !force) return;
7612 46 is_sys_pal = true;
7613 46 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7614 46 hw_palette = &syspal;
7615 46 update_hw_pal = true;
7616 46 }
7617
7618 static uint32_t entered_sys_pal = 0;
7619 46 void enter_sys_pal()
7620 {
7621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(is_sys_pal)
7622 {
7623 if(entered_sys_pal)
7624 ++entered_sys_pal;
7625 return;
7626 }
7627 46 sys_mouse();
7628 46 system_pal(true);
7629 46 ++entered_sys_pal;
7630 46 }
7631 46 void exit_sys_pal()
7632 {
7633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(entered_sys_pal)
7634 {
7635
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(!--entered_sys_pal)
7636 {
7637 46 game_pal();
7638 46 game_mouse();
7639 46 }
7640 46 }
7641 46 }
7642
7643 void switch_out_callback()
7644 {
7645 if (pause_in_background && !MenuOpen)
7646 {
7647 System();
7648 }
7649 }
7650
7651 void switch_in_callback()
7652 {
7653 }
7654
7655 1151 void game_pal()
7656 {
7657 1151 is_sys_pal = false;
7658 1151 entered_sys_pal = 0;
7659 1151 hw_palette = &RAMpal;
7660 1151 update_hw_pal = true;
7661 1151 }
7662
7663 static char bar_str[] = "";
7664
7665 46 void music_pause()
7666 {
7667 //al_pause_duh(tmplayer);
7668 46 zcmusic_pause(zcmusic, ZCM_PAUSE);
7669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(zcmixer->oldtrack)
7670 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7671 46 zc_midi_pause();
7672 46 }
7673
7674 void music_resume()
7675 {
7676 //al_resume_duh(tmplayer);
7677 zcmusic_pause(zcmusic, ZCM_RESUME);
7678 if (zcmixer->oldtrack)
7679 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7680 zc_midi_resume();
7681 }
7682
7683 7912 void music_stop()
7684 {
7685 //al_stop_duh(tmplayer);
7686 //unload_duh(tmusic);
7687 //tmusic=NULL;
7688 //tmplayer=NULL;
7689 7912 zcmusic_stop(zcmusic);
7690 7912 zcmusic_unload_file(zcmusic);
7691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7912 times.
7912 if (zcmixer->oldtrack)
7692 {
7693 zcmusic_stop(zcmixer->oldtrack);
7694 zcmusic_unload_file(zcmixer->oldtrack);
7695 }
7696 7912 zcmixer->newtrack = NULL;
7697 7912 zc_stop_midi();
7698 7912 currmidi=-1;
7699 7912 }
7700
7701 bool reload_fonts = false;
7702 void System()
7703 {
7704 mouse_down = gui_mouse_b();
7705 music_pause();
7706 pause_all_sfx();
7707 MenuOpen = true;
7708 enter_sys_pal();
7709 // FONT *oldfont=font;
7710 // font=tfont;
7711
7712 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7713 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7714
7715 #if DEVLEVEL > 1
7716 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7717 #endif
7718 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7719 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7720 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7721 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7722 clear_keybuf();
7723
7724 clear_bitmap(menu_bmp);
7725 oldscreen = screen;
7726 screen = menu_bmp;
7727
7728 the_player_menu.reset_state();
7729 the_player_menu.position(0, 0);
7730
7731 bool running = true;
7732 bool esc = key[KEY_ESC] || cMbtn();
7733 bool autopop = esc;
7734 do
7735 {
7736 if(reload_fonts)
7737 {
7738 init_custom_fonts();
7739 clear_bitmap(menu_bmp);
7740 broadcast_dialog_message(MSG_DRAW, 0);
7741 reload_fonts = false;
7742 }
7743 if(handle_close_btn_quit())
7744 break;
7745
7746 //update submenus
7747 {
7748 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7749 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7750 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7751 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7752 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7753 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7754 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7755 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7756
7757 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7758 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7759 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7760 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7761 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7762
7763 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7764 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7765 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7766
7767 name_entry_mode_menu.select_only_index(NameEntryMode);
7768
7769 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7770 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7771
7772 bool nocheat = (replay_is_replaying() || !Playing
7773 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7774 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7775 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7776 cheat_menu.chop_index.reset();
7777 if(cheat < 4)
7778 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7779 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7780 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, toogam);
7781 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7782 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7783
7784 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7785 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7786 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7787 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7788 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7789 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7790 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7791 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7792 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7793 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7794 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7795 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7796 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7797 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7798 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7799
7800 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7801 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7802
7803 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7804 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7805
7806 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7807 #ifdef HAS_CURL
7808 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7809 #endif
7810 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7811 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7812 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7813
7814 snapshot_format_menu.select_only_index(SnapshotFormat);
7815 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7816 }
7817
7818 if(debug_enabled)
7819 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7820
7821 if(autopop)
7822 clear_keybuf();
7823 the_player_menu.run(true);
7824 if(autopop)
7825 {
7826 the_player_menu.pop_sub(0, &the_player_menu);
7827 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7828 autopop = false;
7829 update_hw_screen();
7830 }
7831
7832 update_hw_screen();
7833
7834 auto mb = gui_mouse_b();
7835 if(XOR(mb, mouse_down))
7836 {
7837 if(!the_player_menu.has_mouse())
7838 if(mb)
7839 break;
7840 mouse_down = mb;
7841 }
7842
7843 if(input_idle(true) > after_time())
7844 // run Screeen Saver
7845 {
7846 // Screen saver enabled for now.
7847 clear_keybuf();
7848 Matrix(ss_speed, ss_density, 0);
7849 system_pal(true);
7850 sys_mouse();
7851 }
7852
7853 poll_keyboard();
7854 if(esc)
7855 {
7856 if(!key[KEY_ESC])
7857 esc = false;
7858 }
7859
7860 if(keypressed() && !CHECK_ALT) //System hotkeys
7861 {
7862 auto c = peekkey();
7863 bool eatkey = true;
7864 switch(c>>8)
7865 {
7866 //Spare keys used by the menu
7867 case KEY_UP:
7868 case KEY_DOWN:
7869 case KEY_LEFT:
7870 case KEY_RIGHT:
7871 eatkey = false;
7872 break;
7873 case KEY_F1:
7874 onThrottleFPS();
7875 break;
7876 case KEY_F2:
7877 onShowFPS();
7878 break;
7879 case KEY_F6:
7880 onTryQuitMenu();
7881 break;
7882 #ifndef ALLEGRO_MACOSX
7883 case KEY_F9:
7884 onReset();
7885 break;
7886 case KEY_F10:
7887 onExit();
7888 break;
7889 #else
7890 case KEY_F7:
7891 onReset();
7892 break;
7893 case KEY_F8:
7894 onExit();
7895 break;
7896 #endif
7897 case KEY_F12:
7898 onSnapshot();
7899 break;
7900 case KEY_TAB:
7901 onDebug();
7902 break;
7903 case KEY_ESC:
7904 if(!esc)
7905 running = false;
7906 break;
7907 }
7908 if(eatkey)
7909 readkey();
7910 }
7911 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7912 break;
7913 }
7914 while(running);
7915
7916 screen = oldscreen;
7917
7918 mouse_down=gui_mouse_b();
7919 MenuOpen = false;
7920 if(Quit)
7921 {
7922 kill_sfx();
7923 music_stop();
7924 update_hw_screen();
7925 }
7926 else
7927 {
7928 music_resume();
7929 resume_all_sfx();
7930
7931 if(rc)
7932 ringcolor(false);
7933 }
7934 exit_sys_pal();
7935
7936 eat_buttons();
7937
7938 rc=false;
7939 clear_keybuf();
7940
7941 zc_init_apply_cheat_delta();
7942 }
7943
7944 314 void fix_dialogs()
7945 {
7946 314 jwin_center_dialog(about_dlg);
7947 314 jwin_center_dialog(gamepad_dlg);
7948 314 jwin_center_dialog(credits_dlg);
7949 314 jwin_center_dialog(gamemode_dlg);
7950 314 jwin_center_dialog(getnum_dlg);
7951 314 jwin_center_dialog(goto_dlg);
7952 314 jwin_center_dialog(keyboard_control_dlg);
7953 314 jwin_center_dialog(midi_dlg);
7954 314 jwin_center_dialog(quest_dlg);
7955 314 jwin_center_dialog(scrsaver_dlg);
7956 314 jwin_center_dialog(sound_dlg);
7957 314 jwin_center_dialog(triforce_dlg);
7958 314 }
7959
7960 4330 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7961 {
7962
3/4
✓ Branch 0 taken 4330 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4308 times.
✓ Branch 3 taken 22 times.
4330 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7963 }
7964
7965 292 int32_t get_emusic_volume()
7966 {
7967 292 int32_t temp_volume = emusic_volume;
7968
2/4
✓ Branch 0 taken 292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 292 times.
✗ Branch 3 not taken.
292 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7969 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 292 times.
292 if (!zcmusic)
7971 292 return temp_volume;
7972 return (temp_volume * zcmusic->fadevolume) / 10000;
7973 292 }
7974
7975 int32_t get_zcmusicpos()
7976 {
7977 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7978 return debugtracething;
7979 return 0;
7980 }
7981
7982 void set_zcmusicpos(int32_t position)
7983 {
7984 zcmusic_set_curpos(zcmusic, position);
7985 }
7986
7987 void set_zcmusicspeed(int32_t speed)
7988 {
7989 zcmusic_set_speed(zcmusic, speed);
7990 }
7991
7992 int32_t get_zcmusiclen()
7993 {
7994 return zcmusic_get_length(zcmusic);
7995 }
7996
7997 3 void set_zcmusicloop(double start, double end)
7998 {
7999 3 zcmusic_set_loop(zcmusic, start, end);
8000 3 }
8001
8002 64164 void jukebox(int32_t index,int32_t loop)
8003 {
8004
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if (is_headless())
8005 64164 return;
8006
8007 music_stop();
8008
8009 if(index<0) index=MAXMIDIS-1;
8010
8011 if(index>=MAXMIDIS) index=0;
8012
8013 music_stop();
8014
8015 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8016 // stuck notes when a song stops. This fixes it.
8017 if(strcmp(midi_driver->name, "DIGMID")==0)
8018 zc_set_volume(0, 0);
8019
8020 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8021 zc_play_midi(tunes[index].data,loop);
8022
8023 if(tunes[index].start>0)
8024 zc_midi_seek(tunes[index].start);
8025
8026 midi_loop_start = tunes[index].loop_start;
8027 midi_loop_end = tunes[index].loop_end;
8028
8029 currmidi=index;
8030 master_volume(digi_volume, midi_volume);
8031 //midi_paused=false;
8032 64164 }
8033
8034 64164 void jukebox(int32_t index)
8035 {
8036
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index<0) index=MAXMIDIS-1;
8037
8038
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index>=MAXMIDIS) index=0;
8039
8040 // do nothing if it's already playing
8041
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64164 if(index==currmidi && midi_pos>=0)
8042 {
8043 return;
8044 }
8045
8046 64164 jukebox(index,tunes[index].loop);
8047 64164 }
8048
8049 101 void play_DmapMusic()
8050 {
8051
1/2
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
101 if (is_headless())
8052 101 return;
8053
8054 static char tfile[2048];
8055 static int32_t ttrack=0;
8056 bool domidi=false;
8057
8058 int32_t fadeoutframes = 0;
8059 if (zcmusic != NULL)
8060 fadeoutframes = zcmusic->fadeoutframes;
8061
8062 if(DMaps[cur_dmap].tmusic[0]!=0)
8063 {
8064 if(zcmusic==NULL ||
8065 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8066 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8067 {
8068 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8069 {
8070 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8071 {
8072 if (zcmusic != NULL)
8073 {
8074 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8075 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8076 }
8077 }
8078 }
8079 else
8080 {
8081 if (zcmusic != NULL)
8082 {
8083 zcmusic_stop(zcmusic);
8084 zcmusic_unload_file(zcmusic);
8085 zcmusic = NULL;
8086 zcmixer->newtrack = NULL;
8087 }
8088
8089 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8090 zcmixer->newtrack = zcmusic;
8091
8092 if (zcmusic != NULL)
8093 {
8094 zc_stop_midi();
8095 strcpy(tfile, DMaps[cur_dmap].tmusic);
8096 zcmusic_play(zcmusic, emusic_volume);
8097 int32_t temptracks = 0;
8098 temptracks = zcmusic_get_tracks(zcmusic);
8099 temptracks = (temptracks < 2) ? 1 : temptracks;
8100 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8101 zcmusic_change_track(zcmusic, ttrack);
8102 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8103 }
8104 else
8105 {
8106 tfile[0] = 0;
8107 domidi = true;
8108 }
8109 }
8110 }
8111 }
8112 else
8113 {
8114 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8115 {
8116 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8117 }
8118 else
8119 {
8120 domidi = true;
8121 }
8122 }
8123
8124 if(domidi)
8125 {
8126 int32_t m=DMaps[cur_dmap].midi;
8127
8128 switch(m)
8129 {
8130 case 1:
8131 jukebox(ZC_MIDI_OVERWORLD);
8132 break;
8133
8134 case 2:
8135 jukebox(ZC_MIDI_DUNGEON);
8136 break;
8137
8138 case 3:
8139 jukebox(ZC_MIDI_LEVEL9);
8140 break;
8141
8142 default:
8143 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8144 jukebox(m+MIDIOFFSET_DMAP);
8145 else
8146 music_stop();
8147 }
8148 }
8149 101 }
8150
8151 35712 void playLevelMusic()
8152 {
8153
1/2
✓ Branch 0 taken 35712 times.
✗ Branch 1 not taken.
35712 if (is_headless())
8154 35712 return;
8155
8156 int32_t m=hero_scr->screen_midi;
8157
8158 switch(m)
8159 {
8160 case -2:
8161 music_stop();
8162 break;
8163
8164 case -1:
8165 play_DmapMusic();
8166 break;
8167
8168 case 1:
8169 jukebox(ZC_MIDI_OVERWORLD);
8170 break;
8171
8172 case 2:
8173 jukebox(ZC_MIDI_DUNGEON);
8174 break;
8175
8176 case 3:
8177 jukebox(ZC_MIDI_LEVEL9);
8178 break;
8179
8180 default:
8181 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8182 jukebox(m+MIDIOFFSET_MAPSCR);
8183 else
8184 music_stop();
8185 }
8186 35712 }
8187
8188 4330 void master_volume(int32_t dv,int32_t mv)
8189 {
8190
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2322 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 355 times.
✓ Branch 4 taken 2322 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 355 times.
4330 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8191
8192
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2326 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 326 times.
✓ Branch 4 taken 2326 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 326 times.
4330 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8193
8194
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4330 times.
✓ Branch 2 taken 4330 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4330 times.
4330 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8195 4330 int32_t temp_vol = midi_volume;
8196
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 314 times.
4330 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8197 314 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8198 4330 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8199 4330 }
8200
8201 // array of voices, one for each sfx sample in the data file
8202 // 0+ = voice #
8203 // -1 = voice not allocated
8204 314 void Z_init_sound()
8205 {
8206
2/2
✓ Branch 0 taken 80384 times.
✓ Branch 1 taken 314 times.
80698 for(int32_t i=0; i<WAV_COUNT; i++)
8207 80384 sfx_voice[i]=-1;
8208
8209 314 const char* midis[ZC_MIDI_COUNT] = {
8210 "assets/dungeon.mid",
8211 "assets/ending.mid",
8212 "assets/gameover.mid",
8213 "assets/level9.mid",
8214 "assets/overworld.mid",
8215 "assets/title.mid",
8216 "assets/triforce.mid",
8217 };
8218
2/2
✓ Branch 0 taken 2198 times.
✓ Branch 1 taken 314 times.
2512 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8219 {
8220 2198 tunes[i].data = load_midi(midis[i]);
8221
1/2
✓ Branch 0 taken 2198 times.
✗ Branch 1 not taken.
2198 if (!tunes[i].data)
8222 Z_error_fatal("Missing required file %s\n", midis[i]);
8223 2198 }
8224
8225
2/2
✓ Branch 0 taken 79128 times.
✓ Branch 1 taken 314 times.
79442 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8226 79128 tunes[ZC_MIDI_COUNT+j].data=NULL;
8227
8228 314 master_volume(digi_volume,midi_volume);
8229 314 }
8230
8231 // returns number of voices currently allocated
8232 int32_t sfx_count()
8233 {
8234 int32_t c=0;
8235
8236 for(int32_t i=0; i<WAV_COUNT; i++)
8237 if(sfx_voice[i]!=-1)
8238 ++c;
8239
8240 return c;
8241 }
8242
8243 // clean up finished samples
8244 18313259 void sfx_cleanup()
8245 {
8246
2/2
✓ Branch 0 taken 4688194304 times.
✓ Branch 1 taken 18313259 times.
4706507563 for(int32_t i=0; i<WAV_COUNT; i++)
8247
3/4
✓ Branch 0 taken 1267396 times.
✓ Branch 1 taken 4686926908 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267396 times.
4689461700 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8248 {
8249 1267396 deallocate_voice(sfx_voice[i]);
8250 1267396 sfx_voice[i]=-1;
8251 1267396 }
8252 18313259 }
8253
8254 1267561 SAMPLE* sfx_get_sample(int32_t index)
8255 {
8256 // check index
8257
2/4
✓ Branch 0 taken 1267561 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267561 times.
1267561 if (index<=0 || index>=WAV_COUNT)
8258 return nullptr;
8259
8260
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 821314 times.
1267561 if (sfxdat)
8261 {
8262
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8263 {
8264 446247 return (SAMPLE*)sfxdata[index].dat;
8265 }
8266 else
8267 {
8268 return (SAMPLE*)sfxdata[Z35].dat;
8269 }
8270 }
8271 else
8272 {
8273 821314 return &customsfxdata[index];
8274 }
8275
8276 return nullptr;
8277 1267561 }
8278
8279 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8280 // if a voice is already allocated (and/or playing), then it just returns true
8281 // Returns true: voice is allocated
8282 // false: unsuccessful
8283 1880941 bool sfx_init(int32_t index)
8284 {
8285 // check index
8286
3/4
✓ Branch 0 taken 1400265 times.
✓ Branch 1 taken 480676 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1400265 times.
1880941 if(index<=0 || index>=WAV_COUNT)
8287 480676 return false;
8288
8289
2/2
✓ Branch 0 taken 132764 times.
✓ Branch 1 taken 1267501 times.
1400265 if (sfx_voice[index] == -1)
8290 {
8291 1267501 SAMPLE* sample = sfx_get_sample(index);
8292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1267501 times.
1267501 if (!sample)
8293 return false;
8294
8295 1267501 sfx_voice[index] = allocate_voice(sample);
8296 1267501 }
8297
8298 1400265 return sfx_voice[index] != -1;
8299 1880941 }
8300
8301 int32_t sfx_get_default_freq(int32_t index)
8302 {
8303 if (sfxdat)
8304 {
8305 if (index < Z35)
8306 {
8307 return ((SAMPLE*)sfxdata[index].dat)->freq;
8308 }
8309 else
8310 {
8311 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8312 }
8313 }
8314 else
8315 {
8316 return customsfxdata[index].freq;
8317 }
8318 }
8319
8320 int32_t sfx_get_length(int32_t index)
8321 {
8322 if (sfxdat)
8323 {
8324 if (index < Z35)
8325 {
8326 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8327 }
8328 else
8329 {
8330 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8331 }
8332 }
8333 else
8334 {
8335 return int32_t(customsfxdata[index].len);
8336 }
8337 }
8338
8339 // plays an sfx sample
8340 1880941 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8341 {
8342
2/2
✓ Branch 0 taken 1400265 times.
✓ Branch 1 taken 480676 times.
1880941 if(!sfx_init(index))
8343 480676 return;
8344
1/2
✓ Branch 0 taken 1400265 times.
✗ Branch 1 not taken.
1400265 if (!is_headless())
8345 {
8346 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8347 voice_set_pan(sfx_voice[index], pan);
8348
8349 // Only used by ZScript currently
8350 if (freq <= -1)
8351 {
8352 freq = sfx_get_default_freq(index);
8353 }
8354 voice_set_frequency(sfx_voice[index], freq);
8355
8356 // Only used by ZScript currently
8357 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8358 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8359 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8360 voice_set_volume(sfx_voice[index], temp_volume);
8361
8362 int32_t pos = voice_get_position(sfx_voice[index]);
8363
8364 if (restart) voice_set_position(sfx_voice[index], 0);
8365
8366 if (pos <= 0)
8367 voice_start(sfx_voice[index]);
8368 }
8369
8370
3/4
✓ Branch 0 taken 865553 times.
✓ Branch 1 taken 534712 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 865553 times.
1400265 if (restart && replay_is_debug())
8371 {
8372 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8373 865553 const char* sfx_name = sfx_string[index];
8374
2/2
✓ Branch 0 taken 853753 times.
✓ Branch 1 taken 11800 times.
865553 if (strcmp(sfx_name, "Hero is hit") == 0)
8375 11800 sfx_name = "Player is hit";
8376
2/2
✓ Branch 0 taken 853626 times.
✓ Branch 1 taken 127 times.
853753 else if (strcmp(sfx_name, "Hero dies") == 0)
8377 127 sfx_name = "Player dies";
8378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865553 times.
865553 replay_step_comment(fmt::format("sfx {}", sfx_name));
8379 865553 }
8380 1880941 }
8381
8382 // true if sfx is allocated
8383 203255 bool sfx_allocated(int32_t index)
8384 {
8385
3/4
✓ Branch 0 taken 33546 times.
✓ Branch 1 taken 169709 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33546 times.
203255 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8386 }
8387
8388 // start it (in loop mode) if it's not already playing,
8389 // otherwise adjust it to play in loop mode -DD
8390 118471 void cont_sfx(int32_t index)
8391 {
8392
1/2
✓ Branch 0 taken 118471 times.
✗ Branch 1 not taken.
118471 if (is_headless())
8393 118471 return;
8394
8395 if(!sfx_init(index))
8396 {
8397 return;
8398 }
8399
8400 if(voice_get_position(sfx_voice[index])<=0)
8401 {
8402 voice_set_position(sfx_voice[index],0);
8403 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8404 voice_set_volume(sfx_voice[index], sfx_volume);
8405 voice_start(sfx_voice[index]);
8406 }
8407 else
8408 {
8409 adjust_sfx(index, 128, true);
8410 }
8411 118471 }
8412
8413 // adjust parameters while playing
8414 4942 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8415 {
8416
4/6
✓ Branch 0 taken 4505 times.
✓ Branch 1 taken 437 times.
✓ Branch 2 taken 4505 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4505 times.
4942 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8417 4942 return;
8418
8419 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8420 voice_set_pan(sfx_voice[index],pan);
8421 4942 }
8422
8423 // pauses a voice
8424 3252 void pause_sfx(int32_t index)
8425 {
8426
3/6
✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3252 times.
3252 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8427 voice_stop(sfx_voice[index]);
8428 3252 }
8429
8430 // resumes a voice
8431 1370 void resume_sfx(int32_t index)
8432 {
8433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1370 times.
1370 if (is_headless())
8434 1370 return;
8435
8436 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8437 voice_start(sfx_voice[index]);
8438 1370 }
8439
8440 // pauses all active voices
8441 1063 void pause_all_sfx()
8442 {
8443
2/2
✓ Branch 0 taken 272128 times.
✓ Branch 1 taken 1063 times.
273191 for(int32_t i=0; i<WAV_COUNT; i++)
8444
2/2
✓ Branch 0 taken 272126 times.
✓ Branch 1 taken 2 times.
272130 if(sfx_voice[i]!=-1)
8445 2 voice_stop(sfx_voice[i]);
8446 1063 }
8447
8448 // resumes all paused voices
8449 1017 void resume_all_sfx()
8450 {
8451
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8452
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8453 voice_start(sfx_voice[i]);
8454 1017 }
8455
8456 // stops an sfx and deallocates the voice
8457 14621357 void stop_sfx(int32_t index)
8458 {
8459
3/4
✓ Branch 0 taken 14374311 times.
✓ Branch 1 taken 247046 times.
✓ Branch 2 taken 14374311 times.
✗ Branch 3 not taken.
14621357 if(index<=0 || index>=WAV_COUNT)
8460 247046 return;
8461
8462
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 14374264 times.
14374311 if(sfx_voice[index]!=-1)
8463 {
8464 47 deallocate_voice(sfx_voice[index]);
8465 47 sfx_voice[index]=-1;
8466 47 }
8467 14621357 }
8468
8469 // Stops SFX played by Hero's item of the given family
8470 162791 void stop_item_sfx(int32_t family)
8471 {
8472 162791 int32_t id=current_item_id(family);
8473
8474
2/2
✓ Branch 0 taken 161689 times.
✓ Branch 1 taken 1102 times.
162791 if(id<0)
8475 161689 return;
8476
8477 1102 stop_sfx(itemsbuf[id].usesound);
8478 162791 }
8479
8480 9349 void kill_sfx()
8481 {
8482
2/2
✓ Branch 0 taken 2393344 times.
✓ Branch 1 taken 9349 times.
2402693 for(int32_t i=0; i<WAV_COUNT; i++)
8483
2/2
✓ Branch 0 taken 2393286 times.
✓ Branch 1 taken 58 times.
2393402 if(sfx_voice[i]!=-1)
8484 {
8485 58 deallocate_voice(sfx_voice[i]);
8486 58 sfx_voice[i]=-1;
8487 58 }
8488 9349 }
8489
8490 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8491 1182288 int32_t pan(int32_t x)
8492 {
8493
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1182288 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1182288 switch(pan_style)
8494 {
8495 // MONO
8496 case 0:
8497 return 128;
8498
8499 // 1/2
8500 case 1:
8501 1182288 x -= viewport.x;
8502 1182288 return vbound((x>>1)+68,0,255);
8503
8504 // 3/4
8505 case 2:
8506 x -= viewport.x;
8507 return vbound(((x*3)>>2)+36,0,255);
8508
8509 // FULL
8510 case 3:
8511 default:
8512 x -= viewport.x;
8513 return vbound(x,0,255);
8514 }
8515 1182288 }
8516
8517 50408453 bool joybtn(int32_t b)
8518 {
8519
1/2
✓ Branch 0 taken 50408453 times.
✗ Branch 1 not taken.
50408453 if(b == 0)
8520 return false;
8521
1/2
✓ Branch 0 taken 50408453 times.
✗ Branch 1 not taken.
50408453 if (b-1 >= joy[joystick_index].num_buttons)
8522 50408453 return false;
8523
8524 return joy[joystick_index].button[b-1].b !=0;
8525 50408453 }
8526
8527 bool joystick(int32_t s)
8528 {
8529 if(s < 0)
8530 return false;
8531 if (s >= joy[joystick_index].num_sticks)
8532 return false;
8533
8534 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8535 {
8536 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8537 return true;
8538 }
8539 return false;
8540 }
8541
8542 const char* joybtn_name(int32_t b)
8543 {
8544 if (b <= 0 || b > joy[joystick_index].num_buttons)
8545 return "";
8546
8547 return joy[joystick_index].button[b-1].name;
8548 }
8549
8550 const char* joystick_name(int32_t s)
8551 {
8552 if (s < 0 || s >= joy[joystick_index].num_sticks)
8553 return "";
8554
8555 return joy[joystick_index].stick[s].name;
8556 }
8557
8558 int32_t button_pressed()
8559 {
8560 if (joystick_index >= MAX_JOYSTICKS)
8561 return 0;
8562
8563 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8564 {
8565 if(joybtn(i))
8566 return i;
8567 }
8568
8569 return 0;
8570 }
8571
8572 int32_t next_press_key();
8573
8574 int32_t next_joy_input(bool buttons)
8575 {
8576 clear_keybuf();
8577
8578 //first, we need to wait until they're pressing no buttons
8579 for(;;)
8580 {
8581 if(keypressed())
8582 {
8583 switch(readkey()>>8)
8584 {
8585 case KEY_ESC:
8586 return -1;
8587
8588 case KEY_SPACE:
8589 return 0;
8590 }
8591 }
8592
8593 poll_joystick();
8594 bool done = true;
8595
8596 if (buttons)
8597 {
8598 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8599 {
8600 if(joybtn(i)) done = false;
8601 }
8602 }
8603 else
8604 {
8605 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8606 {
8607 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8608 return -2;
8609 }
8610 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8611 {
8612 if(joystick(i)) done = false;
8613 }
8614 }
8615
8616 if(done) break;
8617 rest(1);
8618 }
8619
8620 //now, we need to wait for them to press any button
8621 for(;;)
8622 {
8623 if(keypressed())
8624 {
8625 switch(readkey()>>8)
8626 {
8627 case KEY_ESC:
8628 return -1;
8629
8630 case KEY_SPACE:
8631 return 0;
8632 }
8633 }
8634
8635 poll_joystick();
8636
8637 if (buttons)
8638 {
8639 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8640 {
8641 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8642 return -2;
8643 }
8644 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8645 {
8646 if(joybtn(i))
8647 return i;
8648 }
8649 }
8650 else
8651 {
8652 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8653 {
8654 if(joystick(i))
8655 return i;
8656 }
8657 }
8658 rest(1);
8659 }
8660 }
8661
8662 7887338 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8663 {
8664
2/2
✓ Branch 0 taken 7858907 times.
✓ Branch 1 taken 28431 times.
7887338 bool ret = btn && !flag;
8665 7887338 flag = rawbtn;
8666
8667 7887338 return ret;
8668 }
8669 376944872 static bool rButton(bool &btn, bool &flag)
8670 {
8671
2/2
✓ Branch 0 taken 363026556 times.
✓ Branch 1 taken 13918316 times.
376944872 bool ret = btn && !flag;
8672 376944872 flag = btn;
8673
8674 376944872 return ret;
8675 }
8676 4643423 static bool rButtonPeek(bool btn, bool flag)
8677 {
8678
2/2
✓ Branch 0 taken 4296162 times.
✓ Branch 1 taken 347261 times.
4643423 if(!btn)
8679 {
8680 4296162 return false;
8681 }
8682
2/2
✓ Branch 0 taken 33613 times.
✓ Branch 1 taken 313648 times.
347261 else if(!flag)
8683 {
8684 33613 return true;
8685 }
8686
8687 313648 return false;
8688 4643423 }
8689
8690 // Updated only by keyboard/gamepad.
8691 // If in replay mode, this is set directly by the replay system.
8692 // This should never be read from directly - use control_state instead.
8693 bool raw_control_state[ZC_CONTROL_STATES];
8694
8695 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8696 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8697 // lasts until the next call to load_control_state.
8698 bool control_state[ZC_CONTROL_STATES];
8699 bool disable_control[ZC_CONTROL_STATES];
8700 bool drunk_toggle_state[11];
8701 bool disabledKeys[127];
8702 bool KeyInput[127];
8703 bool KeyPress[127];
8704
8705 bool key_current_frame[127];
8706 bool key_previous_frame[127];
8707
8708 static bool key_system[127];
8709 static bool key_system_previous[127];
8710 static bool key_system_press[127];
8711
8712 bool button_press[ZC_CONTROL_STATES];
8713 bool button_hold[ZC_CONTROL_STATES];
8714
8715 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8716 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8717 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8718 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8719 #define STICK_PRECISION 56 //define your own sensitivity
8720
8721 15667367 void load_control_state()
8722 {
8723 15667367 load_control_called_this_frame = true;
8724
8725
2/2
✓ Branch 0 taken 12464305 times.
✓ Branch 1 taken 3203062 times.
15667367 if (replay_version_check(8, 11))
8726 {
8727
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8728 57655116 down_control_states[i] = raw_control_state[i];
8729 3203062 }
8730
8731
2/2
✓ Branch 0 taken 15667346 times.
✓ Branch 1 taken 21 times.
15667367 if (!replay_is_replaying())
8732 {
8733
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8734
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8735
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8736
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8737
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8747
8748
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8749 {
8750 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8751 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8752 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8753 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8754 }
8755 else
8756 {
8757 21 raw_control_state[14] = false;
8758 21 raw_control_state[15] = false;
8759 21 raw_control_state[16] = false;
8760 21 raw_control_state[17] = false;
8761 }
8762 21 }
8763
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15667362 times.
15667367 if (replay_is_active())
8764 {
8765
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14455662 times.
15667362 if (replay_get_version() < 3)
8766 1211700 replay_poll();
8767
4/4
✓ Branch 0 taken 14455641 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12694266 times.
✓ Branch 3 taken 1761375 times.
14455662 else if (replay_is_replaying() && replay_get_version() < 6)
8768 1761375 replay_peek_input();
8769
4/4
✓ Branch 0 taken 12694266 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9491204 times.
✓ Branch 3 taken 3203062 times.
12694287 else if (replay_is_replaying() && replay_version_check(8, 11))
8770 3203062 replay_peek_input();
8771
2/2
✓ Branch 0 taken 14327420 times.
✓ Branch 1 taken 1339942 times.
15667362 if (replay_get_version() == 8)
8772 1339942 update_keys();
8773 15667362 }
8774
8775 // Some test replay files were made before a serious input bug was fixed, so instead
8776 // of re-doing them or tossing them out, just check for that zplay version.
8777
3/4
✓ Branch 0 taken 15667357 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15545457 times.
15667367 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8778
2/2
✓ Branch 0 taken 282012426 times.
✓ Branch 1 taken 15667357 times.
297679783 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8779 {
8780 282012426 control_state[i] = raw_control_state[i];
8781
4/4
✓ Branch 0 taken 53024022 times.
✓ Branch 1 taken 228988404 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412028 times.
282012426 if (botched_input && !control_state[i])
8782 50412028 down_control_states[i] = false;
8783 282012426 }
8784 15667357 bool did_bad_cutscene_btn = false;
8785
2/2
✓ Branch 0 taken 15667357 times.
✓ Branch 1 taken 282012426 times.
297679783 for(int q = 0; q < 18; ++q)
8786
4/4
✓ Branch 0 taken 13343057 times.
✓ Branch 1 taken 268669369 times.
✓ Branch 2 taken 13341474 times.
✓ Branch 3 taken 1583 times.
282014009 if(control_state[q] && !active_cutscene.can_button(q))
8787 {
8788 1583 control_state[q] = false;
8789 1583 did_bad_cutscene_btn = true;
8790 1583 }
8791
2/2
✓ Branch 0 taken 15666212 times.
✓ Branch 1 taken 1145 times.
15667357 if(did_bad_cutscene_btn)
8792 1145 active_cutscene.error();
8793
8794 15667357 button_press[0]=rButton(control_state[0],button_hold[0]);
8795 15667357 button_press[1]=rButton(control_state[1],button_hold[1]);
8796 15667357 button_press[2]=rButton(control_state[2],button_hold[2]);
8797 15667357 button_press[3]=rButton(control_state[3],button_hold[3]);
8798 15667357 button_press[4]=rButton(control_state[4],button_hold[4]);
8799 15667357 button_press[5]=rButton(control_state[5],button_hold[5]);
8800 15667357 button_press[6]=rButton(control_state[6],button_hold[6]);
8801 15667357 button_press[7]=rButton(control_state[7],button_hold[7]);
8802 15667357 button_press[8]=rButton(control_state[8],button_hold[8]);
8803 15667357 button_press[9]=rButton(control_state[9],button_hold[9]);
8804 15667357 button_press[10]=rButton(control_state[10],button_hold[10]);
8805 15667357 button_press[11]=rButton(control_state[11],button_hold[11]);
8806 15667357 button_press[12]=rButton(control_state[12],button_hold[12]);
8807 15667357 button_press[13]=rButton(control_state[13],button_hold[13]);
8808 15667357 button_press[14]=rButton(control_state[14],button_hold[14]);
8809 15667357 button_press[15]=rButton(control_state[15],button_hold[15]);
8810 15667357 button_press[16]=rButton(control_state[16],button_hold[16]);
8811 15667357 button_press[17]=rButton(control_state[17],button_hold[17]);
8812 15667357 }
8813
8814 // Returns true if any game key is pressed. This is needed because keypressed()
8815 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8816 78788389 bool zc_key_pressed()
8817 //may also need to use zc_getrawkey
8818 {
8819
7/10
✓ Branch 0 taken 63632873 times.
✓ Branch 1 taken 15155516 times.
✓ Branch 2 taken 15155516 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15155516 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12418961 times.
✓ Branch 7 taken 12418961 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4960214 times.
83748603 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8820
4/6
✓ Branch 0 taken 12418961 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12418961 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9455105 times.
✓ Branch 5 taken 9455105 times.
12418961 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8821
4/6
✓ Branch 0 taken 9455105 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9455105 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6256434 times.
✓ Branch 5 taken 6256434 times.
9455105 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8822
4/6
✓ Branch 0 taken 6256434 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6256434 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5369112 times.
✓ Branch 5 taken 5369112 times.
6256434 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8823
1/2
✓ Branch 0 taken 5369112 times.
✗ Branch 1 not taken.
5369112 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8824
3/4
✓ Branch 0 taken 5181935 times.
✓ Branch 1 taken 187177 times.
✓ Branch 2 taken 5181935 times.
✗ Branch 3 not taken.
5369112 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8825
3/4
✓ Branch 0 taken 5035233 times.
✓ Branch 1 taken 146702 times.
✓ Branch 2 taken 5035233 times.
✗ Branch 3 not taken.
5181935 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8826
3/4
✓ Branch 0 taken 5013021 times.
✓ Branch 1 taken 22212 times.
✓ Branch 2 taken 5013021 times.
✗ Branch 3 not taken.
5035233 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8827
3/4
✓ Branch 0 taken 4986652 times.
✓ Branch 1 taken 26369 times.
✓ Branch 2 taken 4986652 times.
✗ Branch 3 not taken.
5013021 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8828
3/4
✓ Branch 0 taken 4979367 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4979367 times.
✗ Branch 3 not taken.
4986652 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8829
3/4
✓ Branch 0 taken 4962128 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 4962128 times.
✗ Branch 3 not taken.
4979367 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8830
3/4
✓ Branch 0 taken 4960308 times.
✓ Branch 1 taken 1820 times.
✓ Branch 2 taken 4960308 times.
✗ Branch 3 not taken.
4962128 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8831
3/4
✓ Branch 0 taken 4960273 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4960273 times.
✗ Branch 3 not taken.
4960308 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8832
2/2
✓ Branch 0 taken 4960214 times.
✓ Branch 1 taken 59 times.
4960273 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8833 140827399 return true;
8834
8835 4960214 return false;
8836 18521867 }
8837
8838 297957993 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8839 {
8840 297957993 bool ret = false, drunkstate = false, rawret = false;;
8841 297957993 bool* flag = &down_control_states[btn];
8842
2/7
✓ Branch 0 taken 279417223 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18540770 times.
297957993 switch(btn)
8843 {
8844 case btnF12:
8845 ret = zc_getkey(KEY_F12, ignoreDisable);
8846 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8847 eatEntirely = false;
8848 break;
8849 case btnF11:
8850 ret = zc_getkey(KEY_F11, ignoreDisable);
8851 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8852 eatEntirely = false;
8853 break;
8854 case btnF5:
8855 ret = zc_getkey(KEY_F5, ignoreDisable);
8856 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8857 eatEntirely = false;
8858 break;
8859 case btnQ:
8860 ret = zc_getkey(KEY_Q, ignoreDisable);
8861 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8862 eatEntirely = false;
8863 break;
8864 case btnI:
8865 ret = zc_getkey(KEY_I, ignoreDisable);
8866 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8867 eatEntirely = false;
8868 break;
8869 case btnM:
8870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18540770 times.
18540770 if(FFCore.kb_typing_mode) return false;
8871 18540770 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8872 18540770 eatEntirely = false;
8873 18540770 break;
8874 default: //control_state[] index
8875
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 279417223 times.
279417223 if(FFCore.kb_typing_mode) return false;
8876
6/6
✓ Branch 0 taken 278037606 times.
✓ Branch 1 taken 1379617 times.
✓ Branch 2 taken 18115859 times.
✓ Branch 3 taken 259921747 times.
✓ Branch 4 taken 18112886 times.
✓ Branch 5 taken 2973 times.
279417223 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8877
2/2
✓ Branch 0 taken 15931751 times.
✓ Branch 1 taken 263482499 times.
279414250 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8878
4/4
✓ Branch 0 taken 248238878 times.
✓ Branch 1 taken 31178345 times.
✓ Branch 2 taken 7136 times.
✓ Branch 3 taken 31171209 times.
310595568 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8879 279417223 rawret = raw_control_state[btn];
8880 279417223 }
8881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297957993 times.
297957993 assert(flag);
8882
2/2
✓ Branch 0 taken 190494786 times.
✓ Branch 1 taken 107463207 times.
297957993 if(press)
8883 {
8884
2/2
✓ Branch 0 taken 4643423 times.
✓ Branch 1 taken 102819784 times.
107463207 if(peek)
8885 4643423 ret = rButtonPeek(ret, *flag);
8886
2/2
✓ Branch 0 taken 94932446 times.
✓ Branch 1 taken 7887338 times.
102819784 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8887 7887338 else ret = rButton(ret, *flag, rawret);
8888 107463207 }
8889
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 297957993 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
297957993 if(eatEntirely && ret) control_state[btn] = false;
8890
4/4
✓ Branch 0 taken 222486855 times.
✓ Branch 1 taken 75471138 times.
✓ Branch 2 taken 222486774 times.
✓ Branch 3 taken 81 times.
297957993 if(drunk && drunkstate) ret = !ret;
8891 297957993 return ret;
8892 297957993 }
8893
8894 15044445 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8895 {
8896 15044445 byte ret = 0;
8897
2/2
✓ Branch 0 taken 10623374 times.
✓ Branch 1 taken 4421071 times.
15044445 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
8898
2/2
✓ Branch 0 taken 14835733 times.
✓ Branch 1 taken 208712 times.
15044445 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
8899
2/2
✓ Branch 0 taken 14837051 times.
✓ Branch 1 taken 207394 times.
15044445 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
8900
2/2
✓ Branch 0 taken 14837051 times.
✓ Branch 1 taken 207394 times.
15044445 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
8901
2/2
✓ Branch 0 taken 14837051 times.
✓ Branch 1 taken 207394 times.
15044445 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
8902
2/2
✓ Branch 0 taken 14837051 times.
✓ Branch 1 taken 207394 times.
15044445 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
8903
2/2
✓ Branch 0 taken 14837051 times.
✓ Branch 1 taken 207394 times.
15044445 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
8904
2/2
✓ Branch 0 taken 14836936 times.
✓ Branch 1 taken 207509 times.
15044445 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
8905 15044445 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8906 }
8907
8908 7675 byte checkIntBtnVal(byte intbtn, byte vals)
8909 {
8910 7675 return intbtn&vals;
8911 }
8912
8913 3769302 bool Up()
8914 {
8915 3769302 return getInput(btnUp);
8916 }
8917 741494 bool Down()
8918 {
8919 741494 return getInput(btnDown);
8920 }
8921 1010991 bool Left()
8922 {
8923 1010991 return getInput(btnLeft);
8924 }
8925 1079780 bool Right()
8926 {
8927 1079780 return getInput(btnRight);
8928 }
8929 530491 bool cAbtn()
8930 {
8931 530491 return getInput(btnA);
8932 }
8933 3306738 bool cBbtn()
8934 {
8935 3306738 return getInput(btnB);
8936 }
8937 bool cSbtn()
8938 {
8939 return getInput(btnS);
8940 }
8941 208608 bool cLbtn()
8942 {
8943 208608 return getInput(btnL);
8944 }
8945 208608 bool cRbtn()
8946 {
8947 208608 return getInput(btnR);
8948 }
8949 bool cPbtn()
8950 {
8951 return getInput(btnP);
8952 }
8953 bool cEx1btn()
8954 {
8955 return getInput(btnEx1);
8956 }
8957 bool cEx2btn()
8958 {
8959 return getInput(btnEx2);
8960 }
8961 bool cEx3btn()
8962 {
8963 return getInput(btnEx3);
8964 }
8965 bool cEx4btn()
8966 {
8967 return getInput(btnEx4);
8968 }
8969 bool AxisUp()
8970 {
8971 return getInput(btnAxisUp);
8972 }
8973 bool AxisDown()
8974 {
8975 return getInput(btnAxisDown);
8976 }
8977 bool AxisLeft()
8978 {
8979 return getInput(btnAxisLeft);
8980 }
8981 bool AxisRight()
8982 {
8983 return getInput(btnAxisRight);
8984 }
8985
8986 bool cMbtn()
8987 {
8988 return getInput(btnM);
8989 }
8990 bool cF12()
8991 {
8992 return getInput(btnF12);
8993 }
8994 bool cF11()
8995 {
8996 return getInput(btnF11);
8997 }
8998 bool cF5()
8999 {
9000 return getInput(btnF5);
9001 }
9002 bool cQ()
9003 {
9004 return getInput(btnQ);
9005 }
9006 bool cI()
9007 {
9008 return getInput(btnI);
9009 }
9010
9011 211058 bool rUp()
9012 {
9013 211058 return getInput(btnUp, true);
9014 }
9015 210847 bool rDown()
9016 {
9017 210847 return getInput(btnDown, true);
9018 }
9019 210651 bool rLeft()
9020 {
9021 210651 return getInput(btnLeft, true);
9022 }
9023 209912 bool rRight()
9024 {
9025 209912 return getInput(btnRight, true);
9026 }
9027 7058 bool rAbtn()
9028 {
9029 7058 return getInput(btnA, true);
9030 }
9031 2410 bool rBbtn()
9032 {
9033 2410 return getInput(btnB, true);
9034 }
9035 14520336 bool rSbtn()
9036 {
9037 14520336 return getInput(btnS, true);
9038 }
9039 18521867 bool rMbtn()
9040 {
9041 18521867 return getInput(btnM, true);
9042 }
9043 185799 bool rLbtn()
9044 {
9045 185799 return getInput(btnL, true);
9046 }
9047 185794 bool rRbtn()
9048 {
9049 185794 return getInput(btnR, true);
9050 }
9051 14520710 bool rPbtn()
9052 {
9053 14520710 return getInput(btnP, true);
9054 }
9055 bool rEx1btn()
9056 {
9057 return getInput(btnEx1, true);
9058 }
9059 bool rEx2btn()
9060 {
9061 return getInput(btnEx2, true);
9062 }
9063 196445 bool rEx3btn()
9064 {
9065 196445 return getInput(btnEx3, true);
9066 }
9067 196445 bool rEx4btn()
9068 {
9069 196445 return getInput(btnEx4, true);
9070 }
9071 bool rAxisUp()
9072 {
9073 return getInput(btnAxisUp, true);
9074 }
9075 bool rAxisDown()
9076 {
9077 return getInput(btnAxisDown, true);
9078 }
9079 bool rAxisLeft()
9080 {
9081 return getInput(btnAxisLeft, true);
9082 }
9083 bool rAxisRight()
9084 {
9085 return getInput(btnAxisRight, true);
9086 }
9087
9088 bool rF11()
9089 {
9090 return getInput(btnF11, true);
9091 }
9092 bool rQ()
9093 {
9094 return getInput(btnQ, true);
9095 }
9096 bool rI()
9097 {
9098 return getInput(btnI, true);
9099 }
9100
9101 37012394 bool DrunkUp()
9102 {
9103 37012394 return getInput(btnUp, false, true);
9104 }
9105 33782365 bool DrunkDown()
9106 {
9107 33782365 return getInput(btnDown, false, true);
9108 }
9109 19757005 bool DrunkLeft()
9110 {
9111 19757005 return getInput(btnLeft, false, true);
9112 }
9113 16788695 bool DrunkRight()
9114 {
9115 16788695 return getInput(btnRight, false, true);
9116 }
9117 15931891 bool DrunkcAbtn()
9118 {
9119 15931891 return getInput(btnA, false, true);
9120 }
9121 15364756 bool DrunkcBbtn()
9122 {
9123 15364756 return getInput(btnB, false, true);
9124 }
9125 14311909 bool DrunkcEx1btn()
9126 {
9127 14311909 return getInput(btnEx1, false, true);
9128 }
9129 14310541 bool DrunkcEx2btn()
9130 {
9131 14310541 return getInput(btnEx2, false, true);
9132 }
9133 bool DrunkcSbtn()
9134 {
9135 return getInput(btnS, false, true);
9136 }
9137 bool DrunkcMbtn()
9138 {
9139 return getInput(btnM, false, true);
9140 }
9141 bool DrunkcLbtn()
9142 {
9143 return getInput(btnL, false, true);
9144 }
9145 bool DrunkcRbtn()
9146 {
9147 return getInput(btnR, false, true);
9148 }
9149 bool DrunkcPbtn()
9150 {
9151 return getInput(btnP, false, true);
9152 }
9153
9154 bool DrunkrUp()
9155 {
9156 return getInput(btnUp, true, true);
9157 }
9158 bool DrunkrDown()
9159 {
9160 return getInput(btnDown, true, true);
9161 }
9162 bool DrunkrLeft()
9163 {
9164 return getInput(btnLeft, true, true);
9165 }
9166 bool DrunkrRight()
9167 {
9168 return getInput(btnRight, true, true);
9169 }
9170 11970559 bool DrunkrAbtn()
9171 {
9172 11970559 return getInput(btnA, true, true);
9173 }
9174 11999201 bool DrunkrBbtn()
9175 {
9176 11999201 return getInput(btnB, true, true);
9177 }
9178 549513 bool DrunkrEx1btn()
9179 {
9180 549513 return getInput(btnEx1, true, true);
9181 }
9182 549314 bool DrunkrEx2btn()
9183 {
9184 549314 return getInput(btnEx2, true, true);
9185 }
9186 bool DrunkrEx3btn()
9187 {
9188 return getInput(btnEx3, true, true);
9189 }
9190 bool DrunkrEx4btn()
9191 {
9192 return getInput(btnEx4, true, true);
9193 }
9194 bool DrunkrSbtn()
9195 {
9196 return getInput(btnS, true, true);
9197 }
9198 bool DrunkrMbtn()
9199 {
9200 return getInput(btnM, true, true);
9201 }
9202 12973910 bool DrunkrLbtn()
9203 {
9204 12973910 return getInput(btnL, true, true);
9205 }
9206 12968596 bool DrunkrRbtn()
9207 {
9208 12968596 return getInput(btnR, true, true);
9209 }
9210 bool DrunkrPbtn()
9211 {
9212 return getInput(btnP, true, true);
9213 }
9214
9215 18903 void eat_buttons()
9216 {
9217 18903 getInput(btnA, true, false, true);
9218 18903 getInput(btnB, true, false, true);
9219 18903 getInput(btnS, true, false, true);
9220 18903 getInput(btnM, true, false, true);
9221 18903 getInput(btnL, true, false, true);
9222 18903 getInput(btnR, true, false, true);
9223 18903 getInput(btnP, true, false, true);
9224 18903 getInput(btnEx1, true, false, true);
9225 18903 getInput(btnEx2, true, false, true);
9226 18903 getInput(btnEx3, true, false, true);
9227 18903 getInput(btnEx4, true, false, true);
9228 18903 }
9229
9230 // Is true for the _first frame_ of a key press.
9231 // But! it is possible that a script manually sets the value of KeyPress,
9232 // in which case it will be restored to the "true" value based on `key_current_frame`
9233 // and `key_previous_frame` on the next frame.
9234 46 bool zc_readkey(int32_t k, bool ignoreDisable)
9235 {
9236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(ignoreDisable) return KeyPress[k];
9237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 switch(k)
9238 {
9239 case KEY_F7:
9240 case KEY_F8:
9241 case KEY_F9:
9242 return KeyPress[k];
9243
9244 default:
9245
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 return KeyPress[k] && !disabledKeys[k];
9246 }
9247 46 }
9248
9249 // Is true for _every frame_ a key is held down.
9250 // But! it is possible that a script manually sets the value of KeyInput,
9251 // in which case it will be restored to the "true" value based on `key_current_frame`
9252 // on the next frame.
9253 bool zc_getkey(int32_t k, bool ignoreDisable)
9254 {
9255 if(ignoreDisable) return KeyInput[k];
9256 switch(k)
9257 {
9258 case KEY_F7:
9259 case KEY_F8:
9260 case KEY_F9:
9261 return KeyInput[k];
9262
9263 default:
9264 return KeyInput[k] && !disabledKeys[k];
9265 }
9266 }
9267
9268 // Reads (and then clears) the current frame key state directly.
9269 // Scripts can also modify `key_current_frame`.
9270 900 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9271 {
9272
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 898 times.
900 if(zc_getrawkey(k, ignoreDisable))
9273 {
9274 2 _key[k]=key[k]=key_current_frame[k]=0;
9275 2 return true;
9276 }
9277 898 _key[k]=key[k]=key_current_frame[k]=0;
9278 898 return false;
9279 900 }
9280
9281 // Reads the current frame key state directly.
9282 // Scripts can also modify `key_current_frame`.
9283 125797876 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9284 {
9285
2/2
✓ Branch 0 taken 107275917 times.
✓ Branch 1 taken 18521959 times.
125797876 if(ignoreDisable) return key_current_frame[k];
9286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18521959 times.
18521959 switch(k)
9287 {
9288 case KEY_F7:
9289 case KEY_F8:
9290 case KEY_F9:
9291 return key_current_frame[k];
9292
9293 default:
9294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18521959 times.
18521959 return key_current_frame[k] && !disabledKeys[k];
9295 }
9296 125797876 }
9297
9298 // Only used for a handful of keys, like tilde and Function keys.
9299 // This state is never read within the game.
9300 // It exists so that all keyboard input still functions during replay,
9301 // without inadvertently doing things like toggling throttling if the player
9302 // presses ~
9303 bool zc_get_system_key(int32_t k)
9304 {
9305 return key_system[k];
9306 }
9307
9308 // True for the _first_ frame of a key press.
9309 166696803 bool zc_read_system_key(int32_t k)
9310 {
9311 166696803 return key_system_press[k];
9312 }
9313
9314 2352277109 bool is_system_key(int32_t k)
9315 {
9316
2/2
✓ Branch 0 taken 2185580306 times.
✓ Branch 1 taken 166696803 times.
2352277109 switch (k)
9317 {
9318 case KEY_BACKQUOTE:
9319 case KEY_CLOSEBRACE:
9320 case KEY_END:
9321 case KEY_HOME:
9322 case KEY_OPENBRACE:
9323 case KEY_PGDN:
9324 case KEY_PGUP:
9325 case KEY_TAB:
9326 case KEY_TILDE:
9327 166696803 return true;
9328 }
9329 2185580306 return is_Fkey(k);
9330 2352277109 }
9331
9332 18521867 void update_system_keys()
9333 {
9334
2/2
✓ Branch 0 taken 2352277109 times.
✓ Branch 1 taken 18521867 times.
2370798976 for (int32_t q = 0; q < 127; ++q)
9335 {
9336
2/2
✓ Branch 0 taken 388959207 times.
✓ Branch 1 taken 1963317902 times.
2352277109 if (!is_system_key(q))
9337 1963317902 continue;
9338
9339 388959207 key_system[q] = key[q];
9340
1/2
✓ Branch 0 taken 388959207 times.
✗ Branch 1 not taken.
388959207 key_system_press[q] = key_system[q] && !key_system_previous[q];
9341 388959207 key_system_previous[q] = key_system[q];
9342 388959207 }
9343 18521867 }
9344
9345 19861809 void update_keys()
9346 {
9347
2/2
✓ Branch 0 taken 2522449743 times.
✓ Branch 1 taken 19861809 times.
2542311552 for (int32_t q = 0; q < 127; ++q)
9348 {
9349 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9350
2/2
✓ Branch 0 taken 2522437043 times.
✓ Branch 1 taken 12700 times.
2522449743 if (!replay_is_replaying())
9351 12700 key_current_frame[q] = key[q];
9352
9353
2/2
✓ Branch 0 taken 2503062512 times.
✓ Branch 1 taken 19387231 times.
2522449743 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9354 2522449743 KeyInput[q] = key_current_frame[q];
9355 2522449743 key_previous_frame[q] = key_current_frame[q];
9356 2522449743 }
9357 19861809 }
9358
9359